From 77d2310b27d75b7f39200bfb65ea5e6154d1bc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 12 Feb 2023 22:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E5=8D=95=E8=A7=A3?= =?UTF-8?q?=E6=9E=90panic=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/form.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/request/form.go b/request/form.go index bfae8ae..7306c04 100644 --- a/request/form.go +++ b/request/form.go @@ -36,21 +36,6 @@ type form struct { // // Date : 00:34 2022/7/3 func (f *form) Parse(ctx *gin.Context, receiver interface{}) error { - var validateFunc = func(parseErr error) error { - if nil != parseErr { - return parseErr - } - receiverIsStruct := false - switch receiver.(type) { - case struct{}: - receiverIsStruct = true - } - if !receiverIsStruct { - // 不是结构体,不验证表单 - return nil - } - return f.checkInstance.Struct(receiver) - } requestBody, _ := ioutil.ReadAll(ctx.Request.Body) // 请求信息写入上下文 @@ -63,18 +48,18 @@ func (f *form) Parse(ctx *gin.Context, receiver interface{}) error { method == http.MethodTrace || method == http.MethodConnect || method == http.MethodOptions { - return validateFunc(ctx.ShouldBindQuery(receiver)) + return ctx.ShouldBindQuery(receiver) } if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete { if ContentType.IsJson(ctx) { - return validateFunc(ctx.ShouldBindJSON(receiver)) + return ctx.ShouldBindJSON(receiver) } if ContentType.IsFormURLEncoded(ctx) { - return validateFunc(ctx.ShouldBind(receiver)) + return ctx.ShouldBind(receiver) } return errors.New(ctx.ContentType() + " is not support")