github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/libpod/define/version.go (about)

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