github.com/outbrain/consul@v1.4.5/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  var (
     9  	// The git commit that was compiled. These will be filled in by the
    10  	// compiler.
    11  	GitCommit   string
    12  	GitDescribe string
    13  
    14  	// The main version number that is being run at the moment.
    15  	//
    16  	// Version must conform to the format expected by github.com/hashicorp/go-version
    17  	// for tests to work.
    18  	Version = "1.4.5"
    19  
    20  	// A pre-release marker for the version. If this is "" (empty string)
    21  	// then it means that it is a final release. Otherwise, this is a pre-release
    22  	// such as "dev" (in development), "beta", "rc1", etc.
    23  	VersionPrerelease = ""
    24  )
    25  
    26  // GetHumanVersion composes the parts of the version in a way that's suitable
    27  // for displaying to humans.
    28  func GetHumanVersion() string {
    29  	version := Version
    30  	if GitDescribe != "" {
    31  		version = GitDescribe
    32  	}
    33  
    34  	release := VersionPrerelease
    35  	if GitDescribe == "" && release == "" {
    36  		release = "dev"
    37  	}
    38  
    39  	if release != "" {
    40  		if !strings.HasSuffix(version, "-"+release) {
    41  			// if we tagged a prerelease version then the release is in the version already
    42  			version += fmt.Sprintf("-%s", release)
    43  		}
    44  		if GitCommit != "" {
    45  			version += fmt.Sprintf(" (%s)", GitCommit)
    46  		}
    47  	}
    48  
    49  	// Strip off any single quotes added by the git information.
    50  	return strings.Replace(version, "'", "", -1)
    51  }