optimize version info out logic

pull/111/head
alimy 2 years ago
parent 3e08e7f90b
commit be03c59338

@ -13,7 +13,10 @@ BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S')
SHA_SHORT := $(shell git rev-parse --short HEAD)
TAGS = ""
LDFLAGS = -X "main.version=${BUILD_VERSION}" -X "main.buildDate=${BUILD_DATE}" -X "main.commitID=${SHA_SHORT}" -w -s
MOD_NAME = github.com/rocboss/paopao-ce
LDFLAGS = -X "${MOD_NAME}/pkg/debug.version=${BUILD_VERSION}" \
-X "${MOD_NAME}/pkg/debug.buildDate=${BUILD_DATE}" \
-X "${MOD_NAME}/pkg/debug.commitID=${SHA_SHORT}" -w -s
all: fmt build

@ -16,6 +16,7 @@ import (
"github.com/rocboss/paopao-ce/internal/service"
"github.com/rocboss/paopao-ce/pkg/app"
"github.com/rocboss/paopao-ce/pkg/convert"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/errcode"
"github.com/rocboss/paopao-ce/pkg/util"
"github.com/sirupsen/logrus"
@ -29,7 +30,7 @@ const MAX_PHONE_CAPTCHA = 10
func Version(c *gin.Context) {
response := app.NewResponse(c)
response.ToResponse(gin.H{
"version": "PaoPao Service v1.0",
"BuildInfo": debug.ReadBuildInfo(),
})
}

@ -11,6 +11,7 @@ import (
"github.com/rocboss/paopao-ce/internal"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/routers"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/util"
)
@ -59,7 +60,7 @@ func main() {
MaxHeaderBytes: 1 << 20,
}
util.PrintHelloBanner(fmt.Sprintf("paopao %s (build:%s %s)", version, commitID, buildDate))
util.PrintHelloBanner(debug.VersionInfo())
fmt.Fprintf(color.Output, "PaoPao service listen on %s\n",
color.GreenString(fmt.Sprintf("http://%s:%s", conf.ServerSetting.HttpIp, conf.ServerSetting.HttpPort)),
)

@ -0,0 +1,25 @@
package debug
import (
"fmt"
)
var version, commitID, buildDate string
type BuildInfo struct {
Version string
Sum string
BuildDate string
}
func VersionInfo() string {
return fmt.Sprintf("paopao %s (build:%s %s)", version, commitID, buildDate)
}
func ReadBuildInfo() *BuildInfo {
return &BuildInfo{
Version: version,
Sum: commitID,
BuildDate: buildDate,
}
}
Loading…
Cancel
Save