bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/_version/version.go (about) 1 // Package version holds some version data common to bosun and scollector. 2 // Most of these values will be inserted at build time with `-ldFlags` directives for official builds. 3 package version // import "bosun.org/_version" 4 5 import ( 6 "fmt" 7 "os" 8 "time" 9 10 "github.com/kardianos/osext" 11 ) 12 13 // These variables will be set at linking time for official builds. 14 // build.go will set date and sha, but `go get` will set none of these. 15 var ( 16 // Version number for official releases Updated manually before each release. 17 Version = "0.9.0-preview" 18 19 // Set to any non-empty value by official release script 20 OfficialBuild string 21 // Date and time of build. Should be in YYYYMMDDHHMMSS format 22 VersionDate string 23 // VersionSHA should be set at build time as the most recent commit hash. 24 VersionSHA string 25 ) 26 27 // Get a string representing the version information for the current binary. 28 func GetVersionInfo(app string) string { 29 var sha, build string 30 version := ShortVersion() 31 if buildTime, err := time.Parse("20060102150405", VersionDate); err == nil { 32 build = " built " + buildTime.Format(time.RFC3339) 33 } else { 34 currentFilePath, err := osext.Executable() 35 if err == nil { 36 info, err := os.Stat(currentFilePath) 37 if err == nil { 38 build = " last modified " + info.ModTime().Format(time.RFC3339) 39 } 40 } 41 } 42 if VersionSHA != "" { 43 sha = fmt.Sprintf(" (%s)", VersionSHA) 44 } 45 return fmt.Sprintf("%s version %s%s%s", app, version, sha, build) 46 } 47 48 func ShortVersion() string { 49 version := Version 50 51 if OfficialBuild == "" { 52 version += "-dev" 53 } 54 55 return version 56 }