I'm using Go and Buffalo to develop an API. When receiving a request, it is possible to automatically map the JSON payload to a struct:
func MyAction(c buffalo.Context) error {
u := &User{}
if err := c.Bind(u); err != nil {
return err
}
u.Name // "Ringo"
u.Email // "ringo@beatles.com"
}
However, it supposes that the payload is of this shape:
{
"name": "Ringo",
"email": "ringo@beatles.com"
}
If for some reason, the incoming payload has a key:
{
"user": {
"name": "Ringo",
"email": "ringo@beatles.com"
}
}
The binding won't work. I couldn't find how to handle this case. How should I approach this ?