feat 历史记录

This commit is contained in:
2026-01-14 18:15:36 +08:00
parent 313a93702e
commit 636008b97d
16 changed files with 58 additions and 66 deletions

View File

@@ -5,7 +5,6 @@ import (
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-gateway/config"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
@@ -43,14 +42,13 @@ func ginLogger(logger *zap.SugaredLogger) gin.HandlerFunc {
func authJwt() gin.HandlerFunc {
return func(c *gin.Context) {
// 如果是Public接口有Token就读没有就算了
public := false
for _, path := range global.PublicPaths {
if strings.HasPrefix(c.Request.URL.Path, path) {
public = true
break
}
pList := strings.SplitN(c.Request.URL.Path, "/", 4)
if len(pList) < 4 || pList[2] == "" {
http_resp.JsonNotFound(c)
return
}
// 如果是Public接口有Token就读没有就算了
public := pList[2] == "open"
token := strings.TrimPrefix(c.GetHeader("Authorization"), "Bearer ")
if token == "" {
@@ -58,16 +56,14 @@ func authJwt() gin.HandlerFunc {
c.Next()
return
}
http_resp.AbortUnauthorized(c)
http_resp.JsonUnauthorized(c)
c.Abort()
return
}
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
if err != nil {
if public {
c.Next()
return
}
http_resp.AbortUnauthorized(c)
http_resp.JsonUnauthorized(c)
c.Abort()
return
}