psu/common/version.go

67 lines
1.2 KiB
Go
Raw Normal View History

2019-07-21 02:00:04 +00:00
package common
import (
"fmt"
"runtime"
"strings"
)
var (
// This is the current version of the client
CurrentVersion = Version{
Major: 0,
Minor: 1,
Patch: 1,
Suffix: "",
}
// The program name
programName = "Portainer Stack Utils"
2019-07-21 02:00:04 +00:00
// commitHash contains the current Git revision. Use Go Releaser to make sure this gets set.
commitHash string
// buildDate contains the date of the current build.
buildDate string
)
type Version struct {
// Major version
Major uint32
// Minor version
Minor uint32
// Patch version
Patch uint32
// Suffix used in version string
// Will be blank for release versions
Suffix string
}
func (v Version) String() string {
2019-07-22 02:50:55 +00:00
if v.Suffix != "" {
return fmt.Sprintf("%d.%d.%d-%s", v.Major, v.Minor, v.Patch, v.Suffix)
} else {
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
}
2019-07-21 02:00:04 +00:00
}
func BuildVersionString() string {
version := "v" + CurrentVersion.String()
if commitHash != "" {
version += "-" + strings.ToUpper(commitHash)
}
osArch := runtime.GOOS + "/" + runtime.GOARCH
date := buildDate
if date == "" {
date = "unknown"
}
return fmt.Sprintf("%s %s %s BuildDate: %s", programName, version, osArch, date)
2019-07-21 02:00:04 +00:00
}