feat jenkins cicd

This commit is contained in:
2025-12-31 23:34:44 +08:00
parent 670140e7d3
commit 01621ec237
32 changed files with 505 additions and 92 deletions

View File

@@ -43,24 +43,35 @@ func ginLogger(logger *zap.SugaredLogger) gin.HandlerFunc {
func authJwt() gin.HandlerFunc {
return func(c *gin.Context) {
authHeader := c.GetHeader("Authorization")
if authHeader == "" {
// 如果是Public接口有Token就读没有就算了
public := false
for _, path := range config.PublicPaths {
if strings.HasPrefix(c.Request.URL.Path, path) {
public = true
break
}
}
token := strings.TrimPrefix(c.GetHeader("Authorization"), "Bearer ")
if token == "" {
if public {
c.Next()
return
}
http_resp.AbortUnauthorized(c)
return
}
parts := strings.Split(authHeader, " ")
if len(parts) != 2 || strings.ToLower(parts[0]) != "bearer" {
http_resp.AbortUnauthorized(c)
return
}
claims, err := utils.ParseToken(parts[1], config.Get().Auth.Secret)
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
if err != nil {
if public {
c.Next()
return
}
http_resp.AbortUnauthorized(c)
return
}
// 这里将Header写到请求中grpc-gateway框架会读取然后传给grpc服务
c.Request.Header.Set("X-Usn", strconv.Itoa(int(claims.USN)))
c.Next()
}

View File

@@ -72,6 +72,7 @@ func initBaseRoute(r *gin.RouterGroup) {
g := r.Group("/gw")
g.POST("/login", http_handler.Login)
g.POST("/refresh_token", http_handler.RefreshToken)
g.GET("/test", http_handler.Test)
}
func initUserPath(r *gin.RouterGroup) {