From 651441b6147ee11b982c07642367ebfe908fe092 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 22 Sep 2024 17:32:26 +0800 Subject: [PATCH] chore: update impl --- common/gin.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/gin.go b/common/gin.go index 767463f5..7173cb34 100644 --- a/common/gin.go +++ b/common/gin.go @@ -32,14 +32,15 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error { contentType := c.Request.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(requestBody, &v) + c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) } else { + c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) err = c.ShouldBind(&v) } if err != nil { return err } // Reset request body - c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) return nil }