github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/libpod/define/version.go (about) 1 package define 2 3 import ( 4 "runtime" 5 "strconv" 6 "time" 7 8 podmanVersion "github.com/containers/podman/v2/version" 9 ) 10 11 // Overwritten at build time 12 var ( 13 // GitCommit is the commit that the binary is being built from. 14 // It will be populated by the Makefile. 15 gitCommit string 16 // BuildInfo is the time at which the binary was built 17 // It will be populated by the Makefile. 18 buildInfo string 19 ) 20 21 // Version is an output struct for API 22 type Version struct { 23 APIVersion string 24 Version string 25 GoVersion string 26 GitCommit string 27 BuiltTime string 28 Built int64 29 OsArch string 30 } 31 32 // GetVersion returns a VersionOutput struct for API and podman 33 func GetVersion() (Version, error) { 34 var err error 35 var buildTime int64 36 if buildInfo != "" { 37 // Converts unix time from string to int64 38 buildTime, err = strconv.ParseInt(buildInfo, 10, 64) 39 40 if err != nil { 41 return Version{}, err 42 } 43 } 44 return Version{ 45 APIVersion: strconv.Itoa(int(podmanVersion.APIVersion.Major)), 46 Version: podmanVersion.Version.String(), 47 GoVersion: runtime.Version(), 48 GitCommit: gitCommit, 49 BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC), 50 Built: buildTime, 51 OsArch: runtime.GOOS + "/" + runtime.GOARCH, 52 }, nil 53 }