golang gin路由器使用中间件,如何绑定体多次?

i7uaboj4  于 5个月前  发布在  Go
关注(0)|答案(1)|浏览(88)

golang gin路由器使用中间件,如何绑定体多次?

func (a AkSk) Check(c *gin.Context) {
    paramsDealed := map[string]string{}

    if err := c.ShouldBind(&paramsDealed); err != nil {
        c.JSON(http.StatusUnauthorized, apis.NewResult(http.StatusUnauthorized, false, err.Error(), ""))
        c.Abort()
    }
}

个字符
第二次则会导致错误。

m4pnthwp

m4pnthwp1#

使用ShouldBindBodyWith。它将请求体存储到上下文中,并在再次调用时重用。
请参阅Try to bind body into different structs了解更多信息。

相关问题