golang gin路由器使用中间件,如何绑定体多次?
func (a AkSk) Check(c *gin.Context) {
paramsDealed := map[string]string{}
if err := c.ShouldBind(¶msDealed); err != nil {
c.JSON(http.StatusUnauthorized, apis.NewResult(http.StatusUnauthorized, false, err.Error(), ""))
c.Abort()
}
}
个字符
第二次则会导致错误。
1条答案
按热度按时间m4pnthwp1#
使用ShouldBindBodyWith。它将请求体存储到上下文中,并在再次调用时重用。
请参阅Try to bind body into different structs了解更多信息。