42 lines
896 B
Go
42 lines
896 B
Go
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
// The git commit that was compiled. These will be filled in by the
|
|
// compiler.
|
|
GitCommit string
|
|
GitDescribe string
|
|
|
|
// Release versions of the build. These will be filled in by one of the
|
|
// build tag-specific files.
|
|
Version = "unknown"
|
|
VersionPrerelease = "unknown"
|
|
)
|
|
|
|
// GetHumanVersion composes the parts of the version in a way that's suitable
|
|
// for displaying to humans.
|
|
func GetHumanVersion() string {
|
|
version := Version
|
|
if GitDescribe != "" {
|
|
version = GitDescribe
|
|
}
|
|
|
|
release := VersionPrerelease
|
|
if GitDescribe == "" && release == "" {
|
|
release = "dev"
|
|
}
|
|
if release != "" {
|
|
version += fmt.Sprintf("-%s", release)
|
|
if GitCommit != "" {
|
|
version += fmt.Sprintf(" (%s)", GitCommit)
|
|
}
|
|
}
|
|
|
|
// Strip off any single quotes added by the git information.
|
|
return strings.Replace(version, "'", "", -1)
|
|
}
|