Documentation
¶
Overview ¶
Package version implements the "version" CLI command.
Index ¶
Constants ¶
const ( // SourceRelease is a build with link-time release values (e.g. goreleaser). SourceRelease = "release" // SourceModule is a build from the module cache: go install/run pkg@version. SourceModule = "module" // SourceVCS is a build in a VCS checkout, with the toolchain's VCS stamp. SourceVCS = "vcs" // SourceLocal is a build from local files with no VCS stamp. SourceLocal = "local" // SourceUnknown is a binary with no module build info at all. SourceUnknown = "unknown" )
Source values: where the binary's source came from, as far as the build recorded it. Reported in JSON as "source"; the text form shows SourceDetail.
Variables ¶
var ( Commit string CommitDate string TreeState string BuiltBy string )
Release metadata injected at link time, for example by goreleaser:
-X github.com/StevenACoffman/anarch-lint/cmd/version.Commit={{ .FullCommit }}
-X github.com/StevenACoffman/anarch-lint/cmd/version.CommitDate={{ .CommitDate }}
-X github.com/StevenACoffman/anarch-lint/cmd/version.TreeState={{ .GitTreeState }}
-X github.com/StevenACoffman/anarch-lint/cmd/version.BuiltBy=goreleaser
A build through the module proxy (goreleaser's gomod.proxy, or go install pkg@version) carries no VCS stamps in its build info, so these are the only way such a binary can report its commit. A non-empty value wins over build info; empty defers to it. The linker silently ignores -X for a variable that does not exist, so renaming one of these breaks the release without an error.
var Version = "dev"
Version is the application version string. When built from a tagged release or installed via "go install", the Go toolchain embeds the module version automatically, and it is read from build info at startup. Override at link time only if the auto-detected value is incorrect:
go build -ldflags "-X 'github.com/StevenACoffman/anarch-lint/cmd/version.Version=v1.2.3'"
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
GitVersion string `json:"gitVersion"`
Source string `json:"source"`
SourceDetail string `json:"sourceDetail"`
ModuleSum string `json:"moduleChecksum"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
BuiltBy string `json:"builtBy"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
ASCIIName string `json:"-"`
Name string `json:"-"`
Description string `json:"-"`
URL string `json:"-"`
}
Info holds build and VCS metadata for structured output.
func GetVersionInfoFrom ¶
GetVersionInfoFrom builds an Info from an explicit BuildInfo value and link stamp. Each field takes the stamp's value when set, then the build info's, then what a pseudo-version encodes, then "unknown". Passing nil and a zero Stamp returns an Info with all VCS fields set to "unknown" and current runtime values for GoVersion, Compiler, and Platform. This is useful for testing without touching global state.
func (*Info) JSONString ¶
JSONString returns the JSON representation of the version info.
type Option ¶
type Option func(i *Info)
Option can be used to customize the Info after it is gathered from the environment.
func WithASCIIName ¶
WithASCIIName allows you to add an ASCII art of the name.
func WithAppDetails ¶
WithAppDetails allows setting the app name and description.
func WithBuiltBy ¶
WithBuiltBy allows to set the builder name/builder system name.