From d9f7c164324a6b2e101ad2b7ee8fa5c65de0894a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 9 May 2016 14:48:07 +0800 Subject: [PATCH] add version from flag Signed-off-by: Bo-Yi Wu --- gorush.go | 4 ++++ gorush/const.go | 5 ----- gorush/version.go | 10 ++++++++-- script/build.sh | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gorush.go b/gorush.go index 3c95734..4f74951 100644 --- a/gorush.go +++ b/gorush.go @@ -17,6 +17,8 @@ func checkInput(token, message string) { } } +var Version = "No Version Provided" + func main() { version := flag.Bool("v", false, "gorush version") confPath := flag.String("c", "", "yaml configuration file path for gorush") @@ -32,6 +34,8 @@ func main() { flag.Parse() + gorush.SetVersion(Version) + if *version { gorush.PrintGoRushVersion() return diff --git a/gorush/const.go b/gorush/const.go index b2edc81..cf8e5da 100644 --- a/gorush/const.go +++ b/gorush/const.go @@ -1,10 +1,5 @@ package gorush -const ( - // Version is gorush server version. - Version = "1.2.1" -) - const ( // PlatFormIos constant is 1 for iOS PlatFormIos = iota + 1 diff --git a/gorush/version.go b/gorush/version.go index cbc4ea7..cd177c6 100644 --- a/gorush/version.go +++ b/gorush/version.go @@ -6,10 +6,16 @@ import ( "runtime" ) +var version string + +func SetVersion(ver string) { + version = ver +} + // PrintGoRushVersion provide print server engine func PrintGoRushVersion() { fmt.Printf(`GoRush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`, - Version, + version, runtime.Compiler, runtime.Version()) } @@ -18,7 +24,7 @@ func PrintGoRushVersion() { func VersionMiddleware() gin.HandlerFunc { // Set out header value for each response return func(c *gin.Context) { - c.Writer.Header().Set("Server-Version", "GoRush/"+Version) + c.Writer.Header().Set("Server-Version", "GoRush/"+version) c.Next() } } diff --git a/script/build.sh b/script/build.sh index 441d2cb..4824484 100755 --- a/script/build.sh +++ b/script/build.sh @@ -10,7 +10,7 @@ for GOOS in $OS; do (test "$GOOS" = "windows") && EXE="gorush.exe" echo "Build: ${GOOS}, Arch: ${GOARCH}, EXE: ${EXE}" - GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w" -o bin/$GOOS/$GOARCH/${EXE} gorush.go; + GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -X main.Version=${VERSION}" -o bin/$GOOS/$GOARCH/${EXE} gorush.go; tar -C bin/$GOOS/$GOARCH -czf bin/gorush-$VERSION-$GOOS-$GOARCH.tar.gz gorush done done