From f6db9e8edba6d79c8347c64df1d0af905d8fe912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 4 Nov 2024 16:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=20wrapperHandle=20->=20Parse?= =?UTF-8?q?Body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/wrapper.go | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/request/wrapper.go b/request/wrapper.go index 9e149cb..85cc7f1 100644 --- a/request/wrapper.go +++ b/request/wrapper.go @@ -8,11 +8,9 @@ package request import ( - "bytes" - "git.zhangdeman.cn/zhangdeman/consts" + "git.zhangdeman.cn/zhangdeman/gin/request/parse_body" "git.zhangdeman.cn/zhangdeman/wrapper" "github.com/gin-gonic/gin" - "io" "strings" ) @@ -140,28 +138,8 @@ func (wh *wrapperHandle) GetDomain(ctx *gin.Context) string { // Date : 11:25 2024/7/26 func (wh *wrapperHandle) ParseBody(ctx *gin.Context) map[string]any { body := map[string]any{} - contentType := wh.GetContentType(ctx, "") - if strings.Contains(contentType, consts.MimeTypeXWWWFormUrlencoded) { // form请求 - if err := ctx.Request.ParseForm(); nil != err { - return body - } - for paramName, itemParam := range ctx.Request.PostForm { - if len(itemParam) > 0 { - body[paramName] = itemParam[0] - } else { - body[paramName] = "" - } - } - return body - } - - if strings.Contains(contentType, consts.MimeTypeJson) || nil != ctx.Request.Body { // json请求 或者非 json请求 存在 body - data, err := io.ReadAll(ctx.Request.Body) - if nil != err { - return body - } - ctx.Request.Body = io.NopCloser(bytes.NewBuffer(data)) - return body + if _, err := parse_body.Execute(ctx, &body); nil != err { + return map[string]any{} } return body