move var Version to config package

This commit is contained in:
Ulric Qin 2021-09-04 19:35:34 +08:00
parent eaacf04c68
commit 086dcad81f
4 changed files with 7 additions and 4 deletions

View File

@ -5,5 +5,5 @@ version=5.0.0-rc7-1
#export GO111MODULE=on #export GO111MODULE=on
#export GOPROXY=https://goproxy.cn #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

View File

@ -2,3 +2,5 @@ package config
// Server周期性去数据库心跳给自己起的名字 // Server周期性去数据库心跳给自己起的名字
const EndpointName = "server_rpc" const EndpointName = "server_rpc"
var Version = "not specified"

View File

@ -37,6 +37,9 @@ func configRoutes(r *gin.Engine) {
guest.GET("/addr", func(c *gin.Context) { guest.GET("/addr", func(c *gin.Context) {
c.String(200, c.Request.RemoteAddr) c.String(200, c.Request.RemoteAddr)
}) })
guest.GET("/version", func(c *gin.Context) {
c.String(200, config.Version)
})
guest.POST("/auth/login", loginPost) guest.POST("/auth/login", loginPost)
guest.GET("/auth/logout", logoutGet) guest.GET("/auth/logout", logoutGet)

View File

@ -26,8 +26,6 @@ import (
"github.com/didi/nightingale/v5/trans" "github.com/didi/nightingale/v5/trans"
) )
var version = "not specified"
var ( var (
vers *bool vers *bool
help *bool help *bool
@ -39,7 +37,7 @@ func init() {
flag.Parse() flag.Parse()
if *vers { if *vers {
fmt.Println("version:", version) fmt.Println("version:", config.Version)
os.Exit(0) os.Exit(0)
} }