Browse Source

feat(api): Add api/version

Resolves #110
lejianwen 1 year ago
parent
commit
44fa22b7e5

+ 9 - 0
.github/workflows/build.yml

@@ -84,6 +84,15 @@ jobs:
84
       - name: tidy
84
       - name: tidy
85
         run: go mod tidy
85
         run: go mod tidy
86
 
86
 
87
+      - name: Get tag version
88
+        run: |
89
+          TAG_VERSION="${GITHUB_REF##*/}"
90
+          VERSION="${TAG_VERSION#v}" 
91
+          echo "VERSION=$VERSION" >> $GITHUB_ENV
92
+
93
+      - name: Write version to resources/version
94
+        run:  echo $VERSION > resources/version
95
+
87
       - name: swag
96
       - name: swag
88
         run: |
97
         run: |
89
           go install github.com/swaggo/swag/cmd/swag@latest
98
           go install github.com/swaggo/swag/cmd/swag@latest

+ 1 - 6
.gitignore

@@ -1,13 +1,8 @@
1
 .idea
1
 .idea
2
 runtime/*
2
 runtime/*
3
 !runtime
3
 !runtime
4
-!runtime/cache
5
 !runtime/cache/.gitkeep
4
 !runtime/cache/.gitkeep
6
 go.sum
5
 go.sum
7
-resources/*
8
-!resources/public/upload/.gitignore
9
-!resources/web
10
-!resources/web2
11
-!resources/i18n
6
+resources/admin
12
 release
7
 release
13
 data
8
 data

+ 29 - 0
docs/api/api_docs.go

@@ -1252,6 +1252,35 @@ const docTemplateapi = `{
1252
                     }
1252
                     }
1253
                 }
1253
                 }
1254
             }
1254
             }
1255
+        },
1256
+        "/version": {
1257
+            "get": {
1258
+                "description": "版本",
1259
+                "consumes": [
1260
+                    "application/json"
1261
+                ],
1262
+                "produces": [
1263
+                    "application/json"
1264
+                ],
1265
+                "tags": [
1266
+                    "首页"
1267
+                ],
1268
+                "summary": "版本",
1269
+                "responses": {
1270
+                    "200": {
1271
+                        "description": "OK",
1272
+                        "schema": {
1273
+                            "$ref": "#/definitions/response.Response"
1274
+                        }
1275
+                    },
1276
+                    "500": {
1277
+                        "description": "Internal Server Error",
1278
+                        "schema": {
1279
+                            "$ref": "#/definitions/response.Response"
1280
+                        }
1281
+                    }
1282
+                }
1283
+            }
1255
         }
1284
         }
1256
     },
1285
     },
1257
     "definitions": {
1286
     "definitions": {

+ 29 - 0
docs/api/api_swagger.json

@@ -1245,6 +1245,35 @@
1245
                     }
1245
                     }
1246
                 }
1246
                 }
1247
             }
1247
             }
1248
+        },
1249
+        "/version": {
1250
+            "get": {
1251
+                "description": "版本",
1252
+                "consumes": [
1253
+                    "application/json"
1254
+                ],
1255
+                "produces": [
1256
+                    "application/json"
1257
+                ],
1258
+                "tags": [
1259
+                    "首页"
1260
+                ],
1261
+                "summary": "版本",
1262
+                "responses": {
1263
+                    "200": {
1264
+                        "description": "OK",
1265
+                        "schema": {
1266
+                            "$ref": "#/definitions/response.Response"
1267
+                        }
1268
+                    },
1269
+                    "500": {
1270
+                        "description": "Internal Server Error",
1271
+                        "schema": {
1272
+                            "$ref": "#/definitions/response.Response"
1273
+                        }
1274
+                    }
1275
+                }
1276
+            }
1248
         }
1277
         }
1249
     },
1278
     },
1250
     "definitions": {
1279
     "definitions": {

+ 19 - 0
docs/api/api_swagger.yaml

@@ -981,6 +981,25 @@ paths:
981
       summary: 用户列表
981
       summary: 用户列表
982
       tags:
982
       tags:
983
       - 群组
983
       - 群组
984
+  /version:
985
+    get:
986
+      consumes:
987
+      - application/json
988
+      description: 版本
989
+      produces:
990
+      - application/json
991
+      responses:
992
+        "200":
993
+          description: OK
994
+          schema:
995
+            $ref: '#/definitions/response.Response'
996
+        "500":
997
+          description: Internal Server Error
998
+          schema:
999
+            $ref: '#/definitions/response.Response'
1000
+      summary: 版本
1001
+      tags:
1002
+      - 首页
984
 securityDefinitions:
1003
 securityDefinitions:
985
   BearerAuth:
1004
   BearerAuth:
986
     in: header
1005
     in: header

+ 23 - 0
http/controller/api/index.go

@@ -7,6 +7,7 @@ import (
7
 	"Gwen/service"
7
 	"Gwen/service"
8
 	"github.com/gin-gonic/gin"
8
 	"github.com/gin-gonic/gin"
9
 	"net/http"
9
 	"net/http"
10
+	"os"
10
 	"time"
11
 	"time"
11
 )
12
 )
12
 
13
 
@@ -61,3 +62,25 @@ func (i *Index) Heartbeat(c *gin.Context) {
61
 	}
62
 	}
62
 	c.JSON(http.StatusOK, gin.H{})
63
 	c.JSON(http.StatusOK, gin.H{})
63
 }
64
 }
65
+
66
+// Version 版本
67
+// @Tags 首页
68
+// @Summary 版本
69
+// @Description 版本
70
+// @Accept  json
71
+// @Produce  json
72
+// @Success 200 {object} response.Response
73
+// @Failure 500 {object} response.Response
74
+// @Router /version [get]
75
+func (i *Index) Version(c *gin.Context) {
76
+	//读取resources/version文件
77
+	v, err := os.ReadFile("resources/version")
78
+	if err != nil {
79
+		response.Fail(c, 101, err.Error())
80
+		return
81
+	}
82
+	response.Success(
83
+		c,
84
+		string(v),
85
+	)
86
+}

+ 16 - 8
http/router/api.go

@@ -21,10 +21,13 @@ func ApiInit(g *gin.Engine) {
21
 
21
 
22
 	frg := g.Group("/api")
22
 	frg := g.Group("/api")
23
 
23
 
24
-	i := &api.Index{}
25
-	frg.GET("/", i.Index)
24
+	{
25
+		i := &api.Index{}
26
+		frg.GET("/", i.Index)
27
+		frg.GET("/version", i.Version)
26
 
28
 
27
-	frg.POST("/heartbeat", i.Heartbeat)
29
+		frg.POST("/heartbeat", i.Heartbeat)
30
+	}
28
 
31
 
29
 	{
32
 	{
30
 		l := &api.Login{}
33
 		l := &api.Login{}
@@ -33,6 +36,7 @@ func ApiInit(g *gin.Engine) {
33
 		frg.POST("/login", l.Login)
36
 		frg.POST("/login", l.Login)
34
 
37
 
35
 	}
38
 	}
39
+
36
 	{
40
 	{
37
 		o := &api.Oauth{}
41
 		o := &api.Oauth{}
38
 		// [method:POST] [uri:/api/oidc/auth]
42
 		// [method:POST] [uri:/api/oidc/auth]
@@ -52,11 +56,15 @@ func ApiInit(g *gin.Engine) {
52
 	if global.Config.App.WebClient == 1 {
56
 	if global.Config.App.WebClient == 1 {
53
 		WebClientRoutes(frg)
57
 		WebClientRoutes(frg)
54
 	}
58
 	}
55
-	au := &api.Audit{}
56
-	//[method:POST] [uri:/api/audit/conn]
57
-	frg.POST("/audit/conn", au.AuditConn)
58
-	//[method:POST] [uri:/api/audit/file]
59
-	frg.POST("/audit/file", au.AuditFile)
59
+
60
+	{
61
+		au := &api.Audit{}
62
+		//[method:POST] [uri:/api/audit/conn]
63
+		frg.POST("/audit/conn", au.AuditConn)
64
+		//[method:POST] [uri:/api/audit/file]
65
+		frg.POST("/audit/file", au.AuditFile)
66
+	}
67
+
60
 	frg.Use(middleware.RustAuth())
68
 	frg.Use(middleware.RustAuth())
61
 	{
69
 	{
62
 		u := &api.User{}
70
 		u := &api.User{}

+ 1 - 0
resources/version

@@ -0,0 +1 @@
1
+v1.0.0