Documentation
¶
Overview ¶
Package buildinfo reports which build of the server is running.
Almost everything here comes from runtime/debug.ReadBuildInfo, so there is no version constant that someone forgets to bump. A binary built by `go build` from a git checkout carries its revision, and since Go 1.24 it carries the tag it was built from as well; one installed by `go install module@v1.2.3` carries that version; one built from a plain directory carries neither and says so.
The one exception ¶
A container image builds from a source tree with no .git in it — copying a repository's history into a build context to learn one string is not a trade worth making — so ReadBuildInfo has nothing to report there. For that case and that case only, Stamp is set by the linker:
go build -ldflags "-X github.com/pacenote-sim/server/internal/buildinfo.Stamp=v1.2.3"
It wins when it is set, because the only thing that sets it is a release build that already knows its tag. Everywhere else it is empty and the build information answers, which is why there is no version constant in this repository to keep in step with a tag.
Index ¶
Constants ¶
const Unknown = "unknown"
Unknown is what every accessor returns when the build carries no such information. It is a word rather than an empty string so an operator reading a diagnostics page sees an answer instead of a gap.
Variables ¶
var Stamp string
Stamp is the version a release build writes in with -ldflags -X, for the builds that carry no version control information of their own. It is empty in every other build, and an empty Stamp changes nothing.
It is a variable rather than a constant because the linker can only write to a variable, and it is exported for the same reason: -X names a symbol.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
// Version is the module version, "v1.2.3", or [Unknown] for a build that
// was not installed from a module proxy.
Version string
// Revision is the full git commit hash, or [Unknown].
Revision string
// Time is the commit time in RFC 3339, or [Unknown].
Time string
// Modified reports whether the working tree had uncommitted changes.
Modified bool
// GoVersion is the toolchain that built the binary.
GoVersion string
// OS and Arch are the target this binary was built for.
OS, Arch string
}
Info is one build, described.
func Read ¶
func Read() Info
Read returns the build information of the running binary. It is read once and cached, so calling it on a request path costs nothing.