buildinfo

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

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

View Source
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

View Source
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.

func (Info) Long

func (i Info) Long() string

Long is the diagnostics line: the short version, the toolchain and the target, as one string.

func (Info) Short

func (i Info) Short() string

Short is the one-line version an operator sees: the module version when there is one, otherwise the first twelve characters of the revision, with "+dirty" appended when the working tree was not clean.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL