make the app version in backend parsing from package.json and git revision

This commit is contained in:
MaysWind
2021-01-12 00:49:19 +08:00
parent c5385ce86b
commit ce7d1f02b7
2 changed files with 25 additions and 4 deletions
+18 -2
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"os"
@@ -9,13 +10,14 @@ import (
"github.com/mayswind/lab/cmd"
)
const labVersion = "0.1.0"
var version string
var commitHash string
func main() {
app := &cli.App{
Name: "lab",
Usage: "A lightweight account book app hosted by yourself.",
Version: labVersion,
Version: getVersion(),
Commands: []*cli.Command{
cmd.WebServer,
cmd.Database,
@@ -34,3 +36,17 @@ func main() {
log.Fatalf("Failed to run lab app with %s: %v", os.Args, err)
}
}
func getVersion() string {
fullVersion := "Local Build"
if version != "" {
fullVersion = version
}
if commitHash != "" {
fullVersion = fmt.Sprintf("%s (%s)", fullVersion, commitHash)
}
return fullVersion
}