Files
podman/libpod/define/version.go
Valentin Rothberg 5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00

54 lines
1.2 KiB
Go

package define
import (
"runtime"
"strconv"
"time"
podmanVersion "github.com/containers/podman/v3/version"
)
// Overwritten at build time
var (
// GitCommit is the commit that the binary is being built from.
// It will be populated by the Makefile.
gitCommit string
// BuildInfo is the time at which the binary was built
// It will be populated by the Makefile.
buildInfo string
)
// Version is an output struct for API
type Version struct {
APIVersion string
Version string
GoVersion string
GitCommit string
BuiltTime string
Built int64
OsArch string
}
// GetVersion returns a VersionOutput struct for API and podman
func GetVersion() (Version, error) {
var err error
var buildTime int64
if buildInfo != "" {
// Converts unix time from string to int64
buildTime, err = strconv.ParseInt(buildInfo, 10, 64)
if err != nil {
return Version{}, err
}
}
return Version{
APIVersion: podmanVersion.APIVersion.String(),
Version: podmanVersion.Version.String(),
GoVersion: runtime.Version(),
GitCommit: gitCommit,
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
Built: buildTime,
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
}, nil
}