This commit is contained in:
Sebastian Mark 2024-11-09 19:14:48 +01:00
parent 13929eb7f9
commit 99d5815052
3 changed files with 21 additions and 11 deletions

View file

@ -1,9 +1,14 @@
package main
import (
"fmt"
"git.smsvc.net/pomodoro/GoTomato/cmd/server"
)
var Version = ""
func main() {
fmt.Println(Version)
server.Start()
}

View file

@ -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

View file

@ -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
}