feat(api): Add api/version

Resolves #110
This commit is contained in:
lejianwen 2025-01-20 20:04:22 +08:00
parent 56b9c66cb8
commit c6f2f2f150
8 changed files with 127 additions and 14 deletions

View File

@ -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

7
.gitignore vendored
View File

@ -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

View File

@ -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": {

View File

@ -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": {

View File

@ -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

View File

@ -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),
)
}

View File

@ -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{}

1
resources/version Normal file
View File

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