github.com/koko1123/flow-go-1@v0.29.6/cmd/build/version.go (about)

     1  // Package build contains information about the build that injected at build-time.
     2  //
     3  // To use this package, simply import it in your program, then add build
     4  // arguments like the following:
     5  //
     6  //	go build -ldflags "-X github.com/koko1123/flow-go-1/cmd/build.semver=v1.0.0"
     7  package build
     8  
     9  // Default value for build-time-injected version strings.
    10  const undefined = "undefined"
    11  
    12  // The following variables are injected at build-time using ldflags.
    13  var (
    14  	semver string
    15  	commit string
    16  )
    17  
    18  // Semver returns the semantic version of this build.
    19  func Semver() string {
    20  	return semver
    21  }
    22  
    23  // Commit returns the commit at which this build was created.
    24  func Commit() string {
    25  	return commit
    26  }
    27  
    28  // IsDefined determines whether a version string is defined. Inputs should
    29  // have been produced from this package.
    30  func IsDefined(v string) bool {
    31  	return v != undefined
    32  }
    33  
    34  // If any of the build-time-injected variables are empty at initialization,
    35  // mark them as undefined.
    36  func init() {
    37  	if len(semver) == 0 {
    38  		semver = undefined
    39  	}
    40  	if len(commit) == 0 {
    41  		commit = undefined
    42  	}
    43  }