feat 历史记录
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package http_gateway
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/http_handler"
|
||||
@@ -52,16 +52,18 @@ func InitRouter() *gin.Engine {
|
||||
r.HandleMethodNotAllowed = true
|
||||
r.NoMethod(func(c *gin.Context) {
|
||||
http_resp.JsonMethodNotAllowed(c)
|
||||
c.Abort()
|
||||
})
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
http_resp.JsonNotFound(c)
|
||||
c.Abort()
|
||||
})
|
||||
|
||||
initBaseRoute(r.Group("/"))
|
||||
|
||||
auth := r.Group("/")
|
||||
auth.Use(authJwt())
|
||||
|
||||
// 网关
|
||||
initBaseRoute(auth)
|
||||
// 用户中心
|
||||
initUserPath(auth)
|
||||
// 奇怪的知识-服务端
|
||||
@@ -72,13 +74,13 @@ func InitRouter() *gin.Engine {
|
||||
|
||||
func initBaseRoute(r *gin.RouterGroup) {
|
||||
g := r.Group("/gw")
|
||||
g.POST("/login", http_handler.Login)
|
||||
g.POST("/refresh_token", http_handler.RefreshToken)
|
||||
g.POST("/open/login", http_handler.Login)
|
||||
g.POST("/open/refresh_token", http_handler.RefreshToken)
|
||||
}
|
||||
|
||||
func initUserPath(r *gin.RouterGroup) {
|
||||
g := r.Group("/user")
|
||||
client, err := service.UserNewClientLB()
|
||||
client, err := grpc_client.UserNewClientLB()
|
||||
if err != nil {
|
||||
log.Errorf("get user conn failed: %v", err)
|
||||
return
|
||||
@@ -95,7 +97,7 @@ func initUserPath(r *gin.RouterGroup) {
|
||||
|
||||
func initQgdzsPath(r *gin.RouterGroup) {
|
||||
g := r.Group("/qgdzs")
|
||||
client, err := service.QgdzsNewClientLB()
|
||||
client, err := grpc_client.QgdzsNewClientLB()
|
||||
if err != nil {
|
||||
log.Errorf("get qgdzs conn failed: %v", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user