2024-10-22 15:18:05 +00:00
|
|
|
package metadata
|
|
|
|
|
2024-11-09 14:59:30 +00:00
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"runtime/debug"
|
|
|
|
"strings"
|
|
|
|
)
|
2024-10-27 21:46:58 +00:00
|
|
|
|
2024-11-09 14:59:30 +00:00
|
|
|
var (
|
|
|
|
GoTomatoVersion = "" // The GoTomato version
|
|
|
|
ProtocolVersion = "" // The protocol version
|
|
|
|
)
|
|
|
|
|
|
|
|
func stripVersionPrefix(version string) string {
|
|
|
|
return strings.TrimLeft(version, "v")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLatestTag() string {
|
|
|
|
bytes, _ := exec.Command("git", "describe", "--tags").Output()
|
|
|
|
output := strings.TrimSpace(string(bytes))
|
|
|
|
return stripVersionPrefix(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set version from runtime/debug.Main.Version
|
|
|
|
// use latest git tag as fallback
|
|
|
|
// allow GoTomatoVersion to be overwritten via ldflags
|
|
|
|
func init() {
|
|
|
|
if GoTomatoVersion == "" {
|
|
|
|
info, _ := debug.ReadBuildInfo()
|
|
|
|
if info.Main.Version != "(devel)" {
|
|
|
|
GoTomatoVersion = stripVersionPrefix(info.Main.Version)
|
|
|
|
} else {
|
|
|
|
GoTomatoVersion = getLatestTag()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version
|
|
|
|
}
|