Documentation
¶
Overview ¶
Package version reports the version and build metadata of the cem binary and of programs that embed cem packages.
It is intended for external consumption. The package is part of the supported public Go API, so it follows the compatibility policy described in CONTRIBUTING.md.
A build can inject metadata with -ldflags -X, for example:
go build -ldflags "\ -X bennypowers.dev/cem/version.Version=v1.2.3 \ -X bennypowers.dev/cem/version.GitCommit=abcdef1 \ -X bennypowers.dev/cem/version.GitTag=v1.2.3" .
When the metadata is absent, Get reads the Go build information. If cem is the main module, it uses that module's version. If cem is embedded as a dependency, it reports the cem dependency version, honoring any Replace directive, rather than the host program's version. If no module version is available, Get assembles a version from GitTag, GitCommit, and GitDirty when they are set, and finally returns "dev".
Usage:
fmt.Println("cem", version.Get())
for key, value := range version.Info() {
fmt.Printf("%s: %s\n", key, value)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Version is the release version, for example "v1.2.3". It is normally // set at build time with -ldflags -X and defaults to "dev". Version = "dev" // GitCommit is the full or abbreviated git commit hash. It is normally // set at build time with -ldflags -X and defaults to "unknown". GitCommit = "unknown" // GitTag is the git tag at build time. It is normally set at build time // with -ldflags -X and defaults to "unknown". GitTag = "unknown" // BuildTime is the RFC 3339 build timestamp. It is normally set at build // time with -ldflags -X and defaults to "unknown". BuildTime = "unknown" // GitDirty is "dirty" when the working tree contained uncommitted changes // at build time. It is normally set at build time with -ldflags -X and // defaults to the empty string. GitDirty = "" )
Functions ¶
func Full ¶
func Full() string
Full returns the version string with the commit hash appended when it is known.
func Get ¶
func Get() string
Get returns the version string for the application.
It prefers the value injected at build time, then a usable version from Go build information, then a string assembled from git metadata, and finally "dev". For build information, it uses the main module version when cem is the main module; otherwise it scans dependencies for the cem module, so embedders report cem's version rather than the host program's version.
Types ¶
This section is empty.