读取结果增加缓存

This commit is contained in:
白茶清欢 2025-05-04 15:16:55 +08:00
parent 927870b11a
commit ecaf448100

View File

@ -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
}