diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08155e7..ef0740b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,6 +84,15 @@ jobs: - name: tidy run: go mod tidy + - name: Get tag version + run: | + TAG_VERSION="${GITHUB_REF##*/}" + VERSION="${TAG_VERSION#v}" + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Write version to resources/version + run: echo $VERSION > resources/version + - name: swag run: | go install github.com/swaggo/swag/cmd/swag@latest diff --git a/.gitignore b/.gitignore index efdbf0e..f2193e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,8 @@ .idea runtime/* !runtime -!runtime/cache !runtime/cache/.gitkeep go.sum -resources/* -!resources/public/upload/.gitignore -!resources/web -!resources/web2 -!resources/i18n +resources/admin release data \ No newline at end of file diff --git a/docs/api/api_docs.go b/docs/api/api_docs.go index 2f6859d..71bae82 100644 --- a/docs/api/api_docs.go +++ b/docs/api/api_docs.go @@ -1252,6 +1252,35 @@ const docTemplateapi = `{ } } } + }, + "/version": { + "get": { + "description": "版本", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "版本", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } } }, "definitions": { diff --git a/docs/api/api_swagger.json b/docs/api/api_swagger.json index 0d81993..c121834 100644 --- a/docs/api/api_swagger.json +++ b/docs/api/api_swagger.json @@ -1245,6 +1245,35 @@ } } } + }, + "/version": { + "get": { + "description": "版本", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "版本", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } } }, "definitions": { diff --git a/docs/api/api_swagger.yaml b/docs/api/api_swagger.yaml index 27bcaa2..eb30f17 100644 --- a/docs/api/api_swagger.yaml +++ b/docs/api/api_swagger.yaml @@ -981,6 +981,25 @@ paths: summary: 用户列表 tags: - 群组 + /version: + get: + consumes: + - application/json + description: 版本 + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + summary: 版本 + tags: + - 首页 securityDefinitions: BearerAuth: in: header diff --git a/http/controller/api/index.go b/http/controller/api/index.go index 5e98367..525ebf5 100644 --- a/http/controller/api/index.go +++ b/http/controller/api/index.go @@ -7,6 +7,7 @@ import ( "Gwen/service" "github.com/gin-gonic/gin" "net/http" + "os" "time" ) @@ -61,3 +62,25 @@ func (i *Index) Heartbeat(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{}) } + +// Version 版本 +// @Tags 首页 +// @Summary 版本 +// @Description 版本 +// @Accept json +// @Produce json +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /version [get] +func (i *Index) Version(c *gin.Context) { + //读取resources/version文件 + v, err := os.ReadFile("resources/version") + if err != nil { + response.Fail(c, 101, err.Error()) + return + } + response.Success( + c, + string(v), + ) +} diff --git a/http/router/api.go b/http/router/api.go index 9b2fe86..deb086f 100644 --- a/http/router/api.go +++ b/http/router/api.go @@ -21,10 +21,13 @@ func ApiInit(g *gin.Engine) { frg := g.Group("/api") - i := &api.Index{} - frg.GET("/", i.Index) + { + i := &api.Index{} + frg.GET("/", i.Index) + frg.GET("/version", i.Version) - frg.POST("/heartbeat", i.Heartbeat) + frg.POST("/heartbeat", i.Heartbeat) + } { l := &api.Login{} @@ -33,6 +36,7 @@ func ApiInit(g *gin.Engine) { frg.POST("/login", l.Login) } + { o := &api.Oauth{} // [method:POST] [uri:/api/oidc/auth] @@ -52,11 +56,15 @@ func ApiInit(g *gin.Engine) { if global.Config.App.WebClient == 1 { WebClientRoutes(frg) } - au := &api.Audit{} - //[method:POST] [uri:/api/audit/conn] - frg.POST("/audit/conn", au.AuditConn) - //[method:POST] [uri:/api/audit/file] - frg.POST("/audit/file", au.AuditFile) + + { + au := &api.Audit{} + //[method:POST] [uri:/api/audit/conn] + frg.POST("/audit/conn", au.AuditConn) + //[method:POST] [uri:/api/audit/file] + frg.POST("/audit/file", au.AuditFile) + } + frg.Use(middleware.RustAuth()) { u := &api.User{} diff --git a/resources/version b/resources/version new file mode 100644 index 0000000..60453e6 --- /dev/null +++ b/resources/version @@ -0,0 +1 @@ +v1.0.0 \ No newline at end of file