75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package version
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
// The git commit that was compiled. This will be filled in by the compiler.
|
|
GitCommit string
|
|
GitDescribe string
|
|
|
|
// Whether cgo is enabled or not; set at build time
|
|
CgoEnabled bool
|
|
|
|
Version = "unknown"
|
|
VersionPrerelease = "unknown"
|
|
)
|
|
|
|
// VersionInfo
|
|
type VersionInfo struct {
|
|
Revision string
|
|
Version string
|
|
VersionPrerelease string
|
|
}
|
|
|
|
func GetVersion() *VersionInfo {
|
|
ver := Version
|
|
rel := VersionPrerelease
|
|
if GitDescribe != "" {
|
|
ver = GitDescribe
|
|
}
|
|
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
|
rel = "dev"
|
|
}
|
|
|
|
return &VersionInfo{
|
|
Revision: GitCommit,
|
|
Version: ver,
|
|
VersionPrerelease: rel,
|
|
}
|
|
}
|
|
|
|
func (c *VersionInfo) VersionNumber() string {
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
return "(version unknown)"
|
|
}
|
|
|
|
version := fmt.Sprintf("%s", c.Version)
|
|
|
|
if c.VersionPrerelease != "" {
|
|
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
|
}
|
|
|
|
return version
|
|
}
|
|
|
|
func (c *VersionInfo) FullVersionNumber(rev bool) string {
|
|
var versionString bytes.Buffer
|
|
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
return "Vault (version unknown)"
|
|
}
|
|
|
|
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
|
|
if c.VersionPrerelease != "" {
|
|
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
|
|
}
|
|
if rev && c.Revision != "" {
|
|
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
|
}
|
|
|
|
return versionString.String()
|
|
}
|