diff --git a/main.go b/main.go index 824311a..6e118a0 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "fmt" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt" @@ -40,10 +39,9 @@ func writeLogger(c *gin.Context) { if method == "POST" { params = c.Request.PostForm.Encode() if params == "" { - // 克隆请求 - req := c.Request.Clone(context.Background()) - // 读取原始请求体内容 - bodyBytes, _ := io.ReadAll(req.Body) + // 请求体 + bodyBytes, _ := io.ReadAll(c.Request.Body) + c.Request.Body = io.NopCloser(strings.NewReader(string(bodyBytes))) // Write body back, so other handler can read it too params = string(bodyBytes) } } @@ -55,7 +53,7 @@ func writeLogger(c *gin.Context) { func JWTAuthMiddleware() gin.HandlerFunc { return func(c *gin.Context) { - go writeLogger(c) + writeLogger(c) // 从请求头中获取 JWT 令牌 tokenString := c.Request.Header.Get("token") diff --git a/worker/redis.go b/worker/redis.go index 6fd1c37..cf8941a 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -88,7 +88,7 @@ func SetHashWithTime(key string, id int, name, email string, duration time.Durat // 设置redis hash,设置过期时间 func SetHash(key string, data map[string]interface{}) bool { ctx := context.Background() - err := redisClient.HMSet(ctx, key, data).Err() + err := redisClient.HSet(ctx, key, data).Err() if err != nil { fmt.Println("%v :Error setting hash: %v", key, err) return false