Skip to content

Commit

Permalink
fix: debug BindJSON request body
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Dec 5, 2023
1 parent fc0c89c commit 7beb4be
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,14 @@ func (ctx *Context) BindJSON(obj interface{}) (err error) {
return errors.New("invalid request")
}

if ctx.Debug().IsDebugMode() {
if ctx.Env().Get("DEBUG_ZOOX_REQUEST_BODY") != "" {
// refernece: golang复用http.request.body - https://zhuanlan.zhihu.com/p/47313038
_, err = ctx.CloneBody()
if err != nil {
return fmt.Errorf("failed to read request body: %v", err)
}

ctx.Logger.Infof("[debug][ctx.BindJSON] body: %v", ctx.bodyBytes)
ctx.Logger.Infof("[debug][ctx.BindJSON] body: %s", ctx.bodyBytes)
}

return json.NewDecoder(ctx.Request.Body).Decode(obj)
Expand Down

0 comments on commit 7beb4be

Please sign in to comment.