From 3ee0bc61bd698688c4e4c6a62f3f1385f9fecc6f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 12 Jun 2024 18:03:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98=E4=B8=8D=E6=8F=92=E5=85=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 58d286b..824311a 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main import ( + "context" "fmt" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt" + "io" "strings" "videoplayer/dao" "videoplayer/handler" @@ -36,12 +38,14 @@ func writeLogger(c *gin.Context) { params = c.Request.URL.RawQuery } if method == "POST" { - var data interface{} - err := c.ShouldBind(&data) - if err != nil { - fmt.Println("bind json failed") + params = c.Request.PostForm.Encode() + if params == "" { + // 克隆请求 + req := c.Request.Clone(context.Background()) + // 读取原始请求体内容 + bodyBytes, _ := io.ReadAll(req.Body) + params = string(bodyBytes) } - params = fmt.Sprintf("%v", data) } res := dao.InsertLogToDB(path, ip, method, params) if res == 0 {