修改jwt拦截处理,添加错误问题

This commit is contained in:
junleea 2025-05-18 14:38:51 +08:00
parent b1205306e4
commit 3c9b36cc07
1 changed files with 10 additions and 10 deletions

16
main.go
View File

@ -111,17 +111,17 @@ func JWTAuthMiddleware() gin.HandlerFunc {
if tokenString == "" { if tokenString == "" {
tokenString = c.Query("token") tokenString = c.Query("token")
} }
//for k, _ := range proto.Url_map { for k, _ := range proto.Url_map {
// if strings.Contains(c.Request.URL.Path, k) { if strings.Contains(c.Request.URL.Path, k) {
// log.Println("need not check token:", c.Request.URL.Path) log.Println("need not check token:", c.Request.URL.Path)
// c.Next()
// return
// }
//}
if proto.Url_map[c.Request.URL.Path] == true { //查看是否在不需要token的url中
c.Next() c.Next()
return return
} }
}
//if proto.Url_map[c.Request.URL.Path] == true { //查看是否在不需要token的url中
// c.Next()
// return
//}
if tokenString == "" { if tokenString == "" {
c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "unauthorized", "error": "token is empty", "code": proto.TokenIsNull}) c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "unauthorized", "error": "token is empty", "code": proto.TokenIsNull})
return return