2015-11-09 18:52:55 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// VersionInfo
|
|
|
|
type VersionInfo struct {
|
2021-12-15 19:38:20 +00:00
|
|
|
Revision string `json:"revision,omitempty"`
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
VersionPrerelease string `json:"version_prerelease,omitempty"`
|
|
|
|
VersionMetadata string `json:"version_metadata,omitempty"`
|
2015-11-09 18:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetVersion() *VersionInfo {
|
|
|
|
ver := Version
|
|
|
|
rel := VersionPrerelease
|
2017-04-28 20:22:00 +00:00
|
|
|
md := VersionMetadata
|
2015-11-09 18:52:55 +00:00
|
|
|
if GitDescribe != "" {
|
|
|
|
ver = GitDescribe
|
|
|
|
}
|
|
|
|
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
|
|
|
rel = "dev"
|
|
|
|
}
|
|
|
|
|
|
|
|
return &VersionInfo{
|
|
|
|
Revision: GitCommit,
|
|
|
|
Version: ver,
|
|
|
|
VersionPrerelease: rel,
|
2017-04-28 20:22:00 +00:00
|
|
|
VersionMetadata: md,
|
2015-11-09 18:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:54:04 +00:00
|
|
|
func (c *VersionInfo) VersionNumber() string {
|
|
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
|
|
return "(version unknown)"
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:38:20 +00:00
|
|
|
version := c.Version
|
2016-09-01 18:54:04 +00:00
|
|
|
|
|
|
|
if c.VersionPrerelease != "" {
|
|
|
|
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
|
|
|
}
|
|
|
|
|
2017-04-28 20:22:00 +00:00
|
|
|
if c.VersionMetadata != "" {
|
|
|
|
version = fmt.Sprintf("%s+%s", version, c.VersionMetadata)
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:54:04 +00:00
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:28:35 +00:00
|
|
|
func (c *VersionInfo) FullVersionNumber(rev bool) 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)
|
2016-11-28 00:28:35 +00:00
|
|
|
}
|
2017-04-28 20:22:00 +00:00
|
|
|
|
|
|
|
if c.VersionMetadata != "" {
|
|
|
|
fmt.Fprintf(&versionString, "+%s", c.VersionMetadata)
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:28:35 +00:00
|
|
|
if rev && c.Revision != "" {
|
|
|
|
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
2015-11-09 18:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return versionString.String()
|
|
|
|
}
|