From 99d5815052280d500878f2f70c196b0214661871 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 9 Nov 2024 19:14:48 +0100 Subject: [PATCH] XXX --- GoTomato.go | 5 +++++ cmd/server/main.go | 4 ++-- internal/metadata/version.go | 23 ++++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/GoTomato.go b/GoTomato.go index 01e3a2e..4146b03 100644 --- a/GoTomato.go +++ b/GoTomato.go @@ -1,9 +1,14 @@ package main import ( + "fmt" + "git.smsvc.net/pomodoro/GoTomato/cmd/server" ) +var Version = "" + func main() { + fmt.Println(Version) server.Start() } diff --git a/cmd/server/main.go b/cmd/server/main.go index 2024fa2..fbb0aae 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -28,7 +28,7 @@ func Start() { // show server and protocl version and exit if *showVersionFlag { - fmt.Printf("GoTomato v%s\n", metadata.GoTomatoVersion) + fmt.Printf("GoTomato v%s\n", metadata.GetVersion()) fmt.Printf("Protocol-Version: %s\n", metadata.ProtocolVersion) os.Exit(0) } @@ -48,7 +48,7 @@ func Start() { r.HandleFunc("/ws", websocket.HandleConnection) go websocket.SendPermanentBroadCastMessage() - helper.Logger.Info("GoTomato started", "version", metadata.GoTomatoVersion) + helper.Logger.Info("GoTomato started", "version", metadata.GetVersion()) helper.Logger.Info("Websocket listening", "address", listen) // start the listener diff --git a/internal/metadata/version.go b/internal/metadata/version.go index 2b080e5..8383907 100644 --- a/internal/metadata/version.go +++ b/internal/metadata/version.go @@ -1,20 +1,25 @@ package metadata import ( - "os/exec" - "strings" + "runtime/debug" ) var ( - GoTomatoVersion = "" // The GoTomato version - ProtocolVersion = "" // The protocol version + version = "" + ProtocolVersion = "0" ) func init() { - if GoTomatoVersion == "" { - output, _ := exec.Command("git", "describe", "--tags").Output() - trimmed_output := strings.TrimSpace(string(output)) // strip newlines - GoTomatoVersion = strings.Replace(trimmed_output, "v", "", 1) // strip leading "v" + info, ok := debug.ReadBuildInfo() + if !ok || info.Main.Version == "" { + version = "unknown" + } else { + if version == "" { + version = info.Main.Version + } } - ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version +} + +func GetVersion() string { + return version }