Skip to content

Commit

Permalink
feat(api): Add api/version
Browse files Browse the repository at this point in the history
Resolves #110
  • Loading branch information
lejianwen committed Jan 20, 2025
1 parent 56b9c66 commit c6f2f2f
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions docs/api/api_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 29 additions & 0 deletions docs/api/api_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
19 changes: 19 additions & 0 deletions docs/api/api_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions http/controller/api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"Gwen/service"
"github.com/gin-gonic/gin"
"net/http"
"os"
"time"
)

Expand Down Expand Up @@ -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),
)
}
24 changes: 16 additions & 8 deletions http/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -33,6 +36,7 @@ func ApiInit(g *gin.Engine) {
frg.POST("/login", l.Login)

}

{
o := &api.Oauth{}
// [method:POST] [uri:/api/oidc/auth]
Expand All @@ -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{}
Expand Down
1 change: 1 addition & 0 deletions resources/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0.0

0 comments on commit c6f2f2f

Please sign in to comment.