type Person struct {
Name string `json:"name" xml:"name" form:"name"`
Pass string `json:"pass" xml:"pass" form:"pass"`
}
app.Post("/", func(c *fiber.Ctx) error {
p := new(Person)
if err := c.BodyParser(p); err != nil {
return err
}
log.Println(p.Name) // john
log.Println(p.Pass) // doe
// ...
})
Above is the code to Parse a POST request with a struct. In my case, the number of POST parameters can be any number. How will it be parsed in that situation?
JSON (application/json)Curl request for multiple parameters
Code:
Form (application/x-www-form-urlencoded)After exploring
go-fibersource code which has custom form data processing implementation at the moment which doesn't seem to support slice of custom type([]Person{}).For more information you can check these links to
go-fibersource code which process form data: 1 2 3Instead we can use
go-playground/formto process form dataCurl request for multiple parameters
Code:
I have raised an
issueandPRatgo-fibergithubrepository which has been merged so below request and code will work now.Curl request for multiple parameters
Code: