From d6bf91c9fdcbafa62282913ca0473cd52009aabf Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Mon, 2 Jun 2025 17:58:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8B=A6=E6=88=AA=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index d9674d0..faec90f 100644 --- a/main.go +++ b/main.go @@ -124,12 +124,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { if proto.Config.TOKEN_USE_REDIS { redisToken := worker.GetRedis(tokenString) if redisToken == "" { - c.AbortWithStatus(200) - c.JSON(200, gin.H{ - "message": "NOT_LOGIN", - "error": "server token is empty", - "code": proto.TokenIsNull, - }) + c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "NOT_LOGIN", "error": "server token is empty", "code": proto.TokenIsNull}) return } } @@ -141,12 +136,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { sId = c.Query("super_id") } if sId == "" { - c.AbortWithStatus(200) - c.JSON(200, gin.H{ - "message": "NOT_LOGIN", - "error": "super_id is empty", - "code": proto.TokenIsNull, - }) + c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "unauthorized", "error": "super_id is empty", "code": proto.TokenIsNull}) return } id, _ := strconv.Atoi(sId) @@ -164,8 +154,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { // 验证令牌 if err != nil || !token.Valid { - c.AbortWithStatus(200) - c.JSON(200, gin.H{ + c.AbortWithStatusJSON(http.StatusOK, gin.H{ "message": "NOT_LOGIN", "error": "Invalid token", "code": proto.TokenExpired, @@ -178,8 +167,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { c.Set("username", token.Claims.(jwt.MapClaims)["username"]) if UserFuncIntercept(int(token.Claims.(jwt.MapClaims)["id"].(float64)), c.Request.URL.Path) { - c.AbortWithStatus(200) - c.JSON(http.StatusOK, gin.H{ + c.AbortWithStatusJSON(http.StatusOK, gin.H{ "message": "no function permission", "error": "no permission", "code": proto.NoPermission,