Sebastian Mark
69e1d3a17d
- set version from runtime/debug.Main.Version - use latest git tag as fallback - allow GoTomatoVersion to be overwritten via ldflags
32 lines
784 B
Go
32 lines
784 B
Go
package metadata
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime/debug"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
GoTomatoVersion = "" // The GoTomato version
|
|
ProtocolVersion = "" // The protocol version
|
|
)
|
|
|
|
func getLatestTag() string {
|
|
output, _ := exec.Command("git", "describe", "--tags").Output()
|
|
stripped_output := strings.TrimSpace(string(output))
|
|
return strings.TrimLeft(stripped_output, "v")
|
|
}
|
|
|
|
// 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()
|
|
GoTomatoVersion = info.Main.Version
|
|
if info.Main.Version == "(devel)" {
|
|
GoTomatoVersion = getLatestTag()
|
|
}
|
|
}
|
|
ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version
|
|
}
|