open-vault/version/version.go

55 lines
1,021 B
Go
Raw Normal View History

2015-11-09 18:52:55 +00:00
package version
import (
"bytes"
"fmt"
)
var (
// The git commit that was compiled. This will be filled in by the compiler.
GitCommit string
GitDescribe string
Version string = "unknown"
VersionPrerelease = "unknown"
)
2015-11-09 18:52:55 +00:00
// 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) String() string {
var versionString bytes.Buffer
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
if c.VersionPrerelease != "" {
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
}
return versionString.String()
}