github.com/containers/podman/v4@v4.9.4/libpod/define/version.go (about) 1 package define 2 3 import ( 4 "runtime" 5 "strconv" 6 "time" 7 8 "github.com/containers/podman/v4/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 Os string 31 } 32 33 // GetVersion returns a VersionOutput struct for API and podman 34 func GetVersion() (Version, error) { 35 var err error 36 var buildTime int64 37 if buildInfo != "" { 38 // Converts unix time from string to int64 39 buildTime, err = strconv.ParseInt(buildInfo, 10, 64) 40 41 if err != nil { 42 return Version{}, err 43 } 44 } 45 return Version{ 46 APIVersion: version.APIVersion[version.Libpod][version.CurrentAPI].String(), 47 Version: version.Version.String(), 48 GoVersion: runtime.Version(), 49 GitCommit: gitCommit, 50 BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC), 51 Built: buildTime, 52 OsArch: runtime.GOOS + "/" + runtime.GOARCH, 53 Os: runtime.GOOS, 54 }, nil 55 }