【发布时间】:2018-05-17 10:37:38
【问题描述】:
我使用 go-chi 作为 HTTP 路由器,我想在另一个方法中重用一个方法
func Registration(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body) // if you delete this line, the user will be created
// ...other code
// if all good then create new user
user.Create(w, r)
}
...
func Create(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
// ...other code
// ... there I get the problem with parse JSON from &b
}
user.Create返回错误"unexpected end of JSON input"
其实,在我执行ioutil.ReadAlluser.Create之后就不再解析JSON了,
在r.Body 中有一个空数组[]我该如何解决这个问题?
【问题讨论】:
标签: http go middleware