github.com/openshift/docker-source-to-images@v1.2.0/pkg/version/version.go (about)

     1  package version
     2  
     3  var (
     4  	// commitFromGit is a constant representing the source version that
     5  	// generated this build. It should be set during build via -ldflags.
     6  	commitFromGit string
     7  	// versionFromGit is a constant representing the version tag that
     8  	// generated this build. It should be set during build via -ldflags.
     9  	versionFromGit string
    10  	// major version
    11  	majorFromGit string
    12  	// minor version
    13  	minorFromGit string
    14  )
    15  
    16  // Info contains versioning information.
    17  type Info struct {
    18  	Major      string `json:"major"`
    19  	Minor      string `json:"minor"`
    20  	GitCommit  string `json:"gitCommit"`
    21  	GitVersion string `json:"gitVersion"`
    22  }
    23  
    24  // Get returns the overall codebase version. It's for detecting what code a
    25  // binary was built from.
    26  func Get() Info {
    27  	return Info{
    28  		Major:      majorFromGit,
    29  		Minor:      minorFromGit,
    30  		GitCommit:  commitFromGit,
    31  		GitVersion: versionFromGit,
    32  	}
    33  }
    34  
    35  // String returns info as a human-friendly version string.
    36  func (info Info) String() string {
    37  	version := info.GitVersion
    38  	if version == "" {
    39  		version = "unknown"
    40  	}
    41  	return version
    42  }