The http request body is always nil. Why is this happening? I am using the gokit toolkit. Below code is part of the handler.
func decodeAddRequest(_ context.Context, r *http1.Request) (interface{}, error) {
req := endpoint.AddRequest{}
p, _ := ioutil.ReadAll(r.Body)
fmt.Printf("%s
", p)
err := json.NewDecoder(r.Body).Decode(&req)
return req, err
}
My POST JSON request looks like this
{
"title": "test test",
"complete": false
}
And what gets saved to the database is
{
"title": "",
"complete": false
}
The type are:
type AddRequest struct {
Todo io.Todo `json:"todo"`
}
type Todo struct {
Id bson.ObjectId `json:"id" bson:"_id"`
Title string `json:"title" bson:"title"`
Complete bool `json:"complete" bson:"complete"`
}