Go net/http请求正文始终为零

Go net/http请求正文始终为零,go,Go,http请求正文始终为零。为什么会这样?我正在使用gokit工具包。下面的代码是处理程序的一部分 func decodeAddRequest(_ context.Context, r *http1.Request) (interface{}, error) { req := endpoint.AddRequest{} p, _ := ioutil.ReadAll(r.Body) fmt.Printf("%s\n", p) err := json.NewDe

http请求正文始终为零。为什么会这样?我正在使用gokit工具包。下面的代码是处理程序的一部分

    func decodeAddRequest(_ context.Context, r *http1.Request) (interface{}, error) {
    req := endpoint.AddRequest{}
    p, _ := ioutil.ReadAll(r.Body)
    fmt.Printf("%s\n", p)
    err := json.NewDecoder(r.Body).Decode(&req)
    return req, err
}
我的POST JSON请求如下所示

{
    "title": "test test",
    "complete": false
}
保存到数据库的是

{
    "title": "",
    "complete": false
}
类型包括:

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"`
}

JSON用于todo项,而不是CreateRequest。取消对todo项目的调用:

err := json.NewDecoder(r.Body).Decode(&req.Todo)

@ThunderCat对此非常陌生,但当我格式化打印请求正文时。这是它打印出来的&{0xc0001740e0 false true{0 0}false false 0x42b13e0}身体在我看来不是零。也许是空的。添加
p,:=ioutil.ReadAll(r.Body);fmt.Printf(“%s\n”,p)
以查看正文中的内容。显示
模型的定义。CreateRequest
。这是打印出来的{“title”:“test test”,“complete”:false}ts=2018-10-28812:56:20.56639Z caller=server.go:105 err=EOF@ThunderCat键入AddRequest struct{Todo io.Todo
json:“Todo”
}键入Todo struct{Id bson.ObjectId
json:“Id”bson:“_id”
Title string
json:“Title”bson:“Title”
json:“Complete”bson:“Complete”}@ThunderCat CreateRequest是上述示例中的AddRequest这很有效。非常感谢。您能详细介绍一下您的解决方案吗