psu/common/version.go

47 lines
973 B
Go
Raw Normal View History

2019-07-21 02:00:04 +00:00
package common
import (
"fmt"
"runtime"
)
var (
2019-08-09 05:28:31 +00:00
// This is the current version of the client. It is set by goreleaser.
version string
2019-07-21 02:00:04 +00:00
// 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
)
func BuildVersionString() string {
osArch := runtime.GOOS + "/" + runtime.GOARCH
2019-08-09 05:39:01 +00:00
if version == "" {
return fmt.Sprintf("%s SNAPSHOT %s", programName, osArch)
}
if commitHash != "" {
version += "+" + commitHash
2019-07-21 02:00:04 +00:00
}
2019-08-09 05:39:01 +00:00
return fmt.Sprintf("%s %s %s BuildDate: %s", programName, version, osArch, buildDate)
2019-07-21 02:00:04 +00:00
}
2019-08-09 19:16:12 +00:00
func BuildUseAgentString() string {
var theVersion = version
if theVersion == "" {
theVersion = "SNAPSHOT"
}
if commitHash != "" {
theVersion += "+" + commitHash
2019-08-09 19:16:12 +00:00
}
return fmt.Sprintf("%s %s (%s/%s)", programName, theVersion, runtime.GOOS, runtime.GOARCH)
}