From 3ab85ef226a2982abe5dee2abf01648dcd3d3138 Mon Sep 17 00:00:00 2001 From: hantmac Date: Thu, 19 Dec 2019 21:16:25 +0800 Subject: [PATCH] Add API GetVersion --- backend/conf/config.yml | 1 + backend/main.go | 2 ++ backend/routes/version.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 backend/routes/version.go diff --git a/backend/conf/config.yml b/backend/conf/config.yml index 60d2bd41..d5503878 100644 --- a/backend/conf/config.yml +++ b/backend/conf/config.yml @@ -32,3 +32,4 @@ task: workers: 4 other: tmppath: "/tmp" +version: v0.4.1 \ No newline at end of file diff --git a/backend/main.go b/backend/main.go index 0d7b7cc1..ace026cc 100644 --- a/backend/main.go +++ b/backend/main.go @@ -176,6 +176,8 @@ func main() { authGroup.POST("/users/:id", routes.PostUser) // 更改用户 authGroup.DELETE("/users/:id", routes.DeleteUser) // 删除用户 authGroup.GET("/me", routes.GetMe) // 获取自己账户 + //release版本 + authGroup.GET("/version", routes.GetVersion) //获取发布的版本 } } diff --git a/backend/routes/version.go b/backend/routes/version.go new file mode 100644 index 00000000..719732ad --- /dev/null +++ b/backend/routes/version.go @@ -0,0 +1,17 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + "github.com/spf13/viper" + "net/http" +) + +func GetVersion(c *gin.Context) { + version := viper.GetString("version") + + c.JSON(http.StatusOK, Response{ + Status: "ok", + Message: "success", + Data: version, + }) +}