diff --git a/build.sh b/build.sh index a8c6ce4ba5c24bdbf961e0526fdb5720309ab1ab..3da6198a2b13a1aeccbb5777d7efa142ac273b8a 100755 --- a/build.sh +++ b/build.sh @@ -5,5 +5,5 @@ version=5.0.0-rc7-1 #export GO111MODULE=on #export GOPROXY=https://goproxy.cn -go build -ldflags "-X main.version=${version}" -o n9e-server main.go +go build -ldflags "-X github.com/didi/nightingale/v5/config.Version=${version}" -o n9e-server main.go diff --git a/config/const.go b/config/const.go index 37a1d4cb5daf2fd573574b82d15cbf4efd179478..b452bf2667d6c8af25f65f1f7bd0cfd08a3f13c8 100644 --- a/config/const.go +++ b/config/const.go @@ -2,3 +2,5 @@ package config // Server周期性去数据库心跳,给自己起的名字 const EndpointName = "server_rpc" + +var Version = "not specified" diff --git a/http/router.go b/http/router.go index 4c57ab030e9a12a4ecb6043ef8ad0bc9f4d10bb6..8f592911f07cc31b6efcbbcdf6c9e8cf760fa4ee 100644 --- a/http/router.go +++ b/http/router.go @@ -37,6 +37,9 @@ func configRoutes(r *gin.Engine) { guest.GET("/addr", func(c *gin.Context) { c.String(200, c.Request.RemoteAddr) }) + guest.GET("/version", func(c *gin.Context) { + c.String(200, config.Version) + }) guest.POST("/auth/login", loginPost) guest.GET("/auth/logout", logoutGet) diff --git a/main.go b/main.go index 7e1613ed9c53ea61875cfbacfd13bef24ca927d2..5ea363c1da687f367615913bf93c8574f79857f7 100644 --- a/main.go +++ b/main.go @@ -26,8 +26,6 @@ import ( "github.com/didi/nightingale/v5/trans" ) -var version = "not specified" - var ( vers *bool help *bool @@ -39,7 +37,7 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("version:", config.Version) os.Exit(0) }