From ecaf4481001e3a4611471d206a0e8b9ef48a1515 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, 4 May 2025 15:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=BB=93=E6=9E=9C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/parse_body/execute.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/request/parse_body/execute.go b/request/parse_body/execute.go index 3110796..8f68fc3 100644 --- a/request/parse_body/execute.go +++ b/request/parse_body/execute.go @@ -59,10 +59,24 @@ func Execute(ctx *gin.Context, receiver any) ([]byte, error) { if _, exist := requestBodyParseAdaptorTable[contentType]; !exist { return nil, errors.New(contentType + " : adaptor not found") } - bodyData, err := ReadBody(ctx) - if nil != err { - return nil, err + var ( + bodyData []byte + err error + exist bool + body any + ) + + bodyKey := "_body_read_result" + if body, exist = ctx.Get(bodyKey); exist && nil != body { + bodyData = body.([]byte) + } else { + if bodyData, err = ReadBody(ctx); nil != err { + return nil, err + } + // 设置读取结果 + ctx.Set(bodyKey, bodyData) } + if err = requestBodyParseAdaptorTable[contentType].Unmarshal(bodyData, receiver); nil != err { return nil, err }