【解决了一个小问题】gin框架中出现如下错误:"[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 500"

POST到数据到一条gin框架的接口后,客户端收到400错误,并且返回了业务中返回的“decode json fail”。

关键代码是:

func report(c *gin.Context) {
    req := pb.ReportRequest{}
    err := c.BindJSON(&req)
    if err != nil {
        c.JSON(200, gin.H{"code":1,"msg":"decode json fail"})
        return
    }
}

饶了一大圈,最后输出了err的信息,原来是JSON的格式与PB的格式不匹配。
修改PB的定义后重新编译,问题解决。
日志打不全,害死人。低级错误!

posted on 2020-05-27 11:07  ahfuzhang  阅读(4155)  评论(0编辑  收藏  举报