2015-11-09 18:52:55 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-08-11 00:01:15 +00:00
|
|
|
var (
|
|
|
|
// The git commit that was compiled. This will be filled in by the compiler.
|
|
|
|
GitCommit string
|
|
|
|
GitDescribe string
|
|
|
|
|
2016-08-11 21:23:47 +00:00
|
|
|
Version = "unknown"
|
|
|
|
VersionPrerelease = "unknown"
|
2016-08-11 00:01:15 +00:00
|
|
|
)
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:54:04 +00:00
|
|
|
func (c *VersionInfo) VersionNumber() string {
|
|
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
|
|
return "(version unknown)"
|
|
|
|
}
|
|
|
|
|
2016-09-01 19:23:23 +00:00
|
|
|
version := fmt.Sprintf("%s", c.Version)
|
2016-09-01 18:54:04 +00:00
|
|
|
|
|
|
|
if c.VersionPrerelease != "" {
|
|
|
|
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
|
|
|
}
|
|
|
|
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VersionInfo) FullVersionNumber() string {
|
2015-11-09 18:52:55 +00:00
|
|
|
var versionString bytes.Buffer
|
|
|
|
|
2016-08-25 20:56:47 +00:00
|
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
2016-09-01 18:54:04 +00:00
|
|
|
return "Vault (version unknown)"
|
2016-08-25 20:56:47 +00:00
|
|
|
}
|
2016-09-01 18:54:04 +00:00
|
|
|
|
2015-11-09 18:52:55 +00:00
|
|
|
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()
|
|
|
|
}
|