2021-09-17 19:43:22 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-03-12 01:34:38 -05:00
|
|
|
"runtime/debug"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultVersion = "0.0.0"
|
|
|
|
defaultCommit = "HEAD"
|
|
|
|
defaultBuild = "0000-01-01:00:00+00:00"
|
2021-09-17 19:43:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-03-12 01:34:38 -05:00
|
|
|
// Version is the tagged release version in the form <major>.<minor>.<patch>
|
|
|
|
// following semantic versioning and is overwritten by the build system.
|
|
|
|
Version = defaultVersion
|
2021-09-17 19:43:22 -04:00
|
|
|
|
2023-03-12 01:34:38 -05:00
|
|
|
// Commit is the commit sha of the build (normally from Git) and is overwritten
|
|
|
|
// by the build system.
|
|
|
|
Commit = defaultCommit
|
|
|
|
|
|
|
|
// Build is the date and time of the build as an RFC3339 formatted string
|
|
|
|
// and is overwritten by the build system.
|
|
|
|
Build = defaultBuild
|
2021-09-17 19:43:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// FullVersion display the full version and build
|
|
|
|
func FullVersion() string {
|
2023-03-12 01:34:38 -05:00
|
|
|
var sb strings.Builder
|
|
|
|
|
|
|
|
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
|
|
|
|
|
|
|
|
if !isDefault {
|
|
|
|
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
|
|
|
|
}
|
|
|
|
|
|
|
|
if info, ok := debug.ReadBuildInfo(); ok {
|
|
|
|
if isDefault {
|
|
|
|
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
|
|
|
|
}
|
|
|
|
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
|
|
|
|
if info.Main.Sum != "" {
|
|
|
|
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.String()
|
2021-09-17 19:43:22 -04:00
|
|
|
}
|