Bladeren bron

改目录名称,迁移svc-agent

qdy 3 maanden geleden
bovenliggende
commit
b080078440
5 gewijzigde bestanden met toevoegingen van 7 en 59 verwijderingen
  1. BIN
      .DS_Store
  2. 0
    55
      auth/authentication.go
  3. 2
    1
      go.mod
  4. 2
    0
      go.sum
  5. 3
    3
      main.go

BIN
.DS_Store Bestand weergeven


+ 0
- 55
auth/authentication.go Bestand weergeven

@@ -1,55 +0,0 @@
1
-package auth
2
-
3
-import (
4
-	"net/http"
5
-	"strings"
6
-
7
-	"github.com/gin-gonic/gin"
8
-
9
-	"git.x2erp.com/qdy/go-base/config"
10
-)
11
-
12
-func AuthMiddleware() gin.HandlerFunc {
13
-	return func(c *gin.Context) {
14
-		// 从 Header 中获取 token
15
-		authHeader := c.GetHeader("Authorization")
16
-		if authHeader == "" {
17
-			c.JSON(http.StatusUnauthorized, gin.H{
18
-				"success": false,
19
-				"error":   "Authorization header is required",
20
-			})
21
-			c.Abort()
22
-			return
23
-		}
24
-
25
-		// 检查 Bearer token 格式
26
-		parts := strings.Split(authHeader, " ")
27
-		if len(parts) != 2 || parts[0] != "Bearer" {
28
-			c.JSON(http.StatusUnauthorized, gin.H{
29
-				"success": false,
30
-				"error":   "Authorization header format must be Bearer {token}",
31
-			})
32
-			c.Abort()
33
-			return
34
-		}
35
-
36
-		tokenString := parts[1]
37
-		configTokenString := config.GetConfig().GetAuth().Token
38
-
39
-		// 比较 token 是否相等
40
-		if tokenString != configTokenString {
41
-			c.JSON(http.StatusUnauthorized, gin.H{
42
-				"success": false,
43
-				"error":   "Invalid token",
44
-			})
45
-			c.Abort()
46
-			return
47
-		}
48
-
49
-		// Token 验证通过,可以存储一些上下文信息
50
-		c.Set("authenticated", true)
51
-		c.Set("authType", "token")
52
-
53
-		c.Next()
54
-	}
55
-}

+ 2
- 1
go.mod Bestand weergeven

@@ -4,7 +4,7 @@ go 1.25.4
4 4
 
5 5
 require (
6 6
 	git.x2erp.com/qdy/go-base v0.1.44
7
-	git.x2erp.com/qdy/go-db v0.1.42
7
+	git.x2erp.com/qdy/go-db v0.1.45
8 8
 )
9 9
 
10 10
 require (
@@ -21,6 +21,7 @@ require (
21 21
 	github.com/go-playground/validator/v10 v10.27.0 // indirect
22 22
 	github.com/go-redis/redis/v8 v8.11.5 // indirect
23 23
 	github.com/go-resty/resty/v2 v2.17.0 // indirect
24
+	github.com/go-sql-driver/mysql v1.9.3 // indirect
24 25
 	github.com/goccy/go-json v0.10.2 // indirect
25 26
 	github.com/goccy/go-yaml v1.18.0 // indirect
26 27
 	github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect

+ 2
- 0
go.sum Bestand weergeven

@@ -8,6 +8,8 @@ git.x2erp.com/qdy/go-base v0.1.44 h1:xHpMppSNj79lqdUc+lmgGXOgEvHyNotUayoe5/hHWr4
8 8
 git.x2erp.com/qdy/go-base v0.1.44/go.mod h1:Q+YLwpCoU8CVSnzATLdz2LAzVMlz/CEGzo8DePf7cug=
9 9
 git.x2erp.com/qdy/go-db v0.1.42 h1:WOnu5dPkKAoZXITLPUxFZO8OQhs1gliNW29HSlBsSi4=
10 10
 git.x2erp.com/qdy/go-db v0.1.42/go.mod h1:qTzxo5oTWLhNcaPHRX/WRuX0ROTSQGIXQFMmJHI6VKM=
11
+git.x2erp.com/qdy/go-db v0.1.45 h1:2rrUeX/zwTkVDKKwfaXnM5tD5HU1CrlxpLDzl8itOh8=
12
+git.x2erp.com/qdy/go-db v0.1.45/go.mod h1:Wwe1GmAhGe5nmZhg/Db3GXeqk1dZ3mirZ7h8dYdyl2o=
11 13
 github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 h1:Gt0j3wceWMwPmiazCa8MzMA0MfhmPIz0Qp0FJ6qcM0U=
12 14
 github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0/go.mod h1:Ot/6aikWnKWi4l9QB7qVSwa8iMphQNqkWALMoNT3rzM=
13 15
 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 h1:B+blDbyVIG3WaikNxPnhPiJ1MThR03b3vKGtER95TP4=

+ 3
- 3
main.go Bestand weergeven

@@ -9,7 +9,7 @@ import (
9 9
 
10 10
 	"git.x2erp.com/qdy/go-base/config"
11 11
 	"git.x2erp.com/qdy/go-base/micro"
12
-	mymiddleware "git.x2erp.com/qdy/go-base/myMiddleware"
12
+	"git.x2erp.com/qdy/go-base/mymiddleware"
13 13
 	"git.x2erp.com/qdy/go-db/factory/database"
14 14
 	"git.x2erp.com/qdy/go-db/myhandle"
15 15
 	"git.x2erp.com/qdy/go-service-agent/functions"
@@ -57,7 +57,7 @@ func startMicroService() {
57 57
 	webService := micro.StartStandalone(cfg)
58 58
 
59 59
 	// 注册HTTP路由到webService
60
-	registerRoutes(webService, dbFactory, cfg)
60
+	registerRoutes(webService, dbFactory)
61 61
 
62 62
 	// 等待服务运行
63 63
 	log.Printf("Service started successfully")
@@ -85,7 +85,7 @@ func getServiceMode(cfg config.IConfig) string {
85 85
 }
86 86
 
87 87
 // 注册所有路由
88
-func registerRoutes(webService web.Service, dbFactory *database.DBFactory, cfg config.IConfig) {
88
+func registerRoutes(webService web.Service, dbFactory *database.DBFactory) {
89 89
 
90 90
 	// 查询接口 - JSON
91 91
 	webService.Handle("/api/query/json", mymiddleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Laden…
Annuleren
Opslaan