buildinfo

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package buildinfo resolves what a binary reports about its own build: the version, commit, build time and Go version. The linker's -X stamps win when a build passed them (the Makefile and the release build do); otherwise the module version and VCS metadata the Go toolchain embeds stand in, which is what a `go install` build has; and a build with neither reports the defaults.

Index

Constants

View Source
const (
	// Unversioned is the version of a build no release tag identifies.
	Unversioned = "dev"
	// Unknown is a commit, build time or Go version nothing recorded.
	Unknown = "unknown"
	// Dirty is appended to the commit of a build from a modified working tree,
	// as `git describe --dirty` appends it to the Makefile's version.
	Dirty = "-dirty"
)

Variables

This section is empty.

Functions

func Released

func Released(version string) bool

Released reports whether a module version names a release tag: one the toolchain stamped that is a semantic version and not a pseudo-version, which identifies a commit rather than a release.

func ShortRevision

func ShortRevision(revision string) string

ShortRevision abbreviates a commit hash to the length it is reported at.

func Stamped

func Stamped(version string) bool

Stamped reports whether the toolchain recorded a version for a module: it leaves "" for a build outside module mode and "(devel)" for the main module of an unversioned build or a directory replacement.

Types

type Info

type Info struct {
	// Version is the release tag the build is of, or Unversioned.
	Version string
	// Commit is the short commit hash, Dirty appended for a modified tree, or Unknown.
	Commit string
	// BuildTime is when the build happened, or the commit's time when only that
	// is recorded, in the Makefile's format; Unknown when neither is.
	BuildTime string
	// GoVersion is the toolchain that built the binary.
	GoVersion string
}

Info is what a binary reports about its build.

func Resolve

func Resolve(stamps Stamps) Info

Resolve reports the running binary's build from stamps and the build information the toolchain embedded in it.

func ResolveFrom

func ResolveFrom(stamps Stamps, info *debug.BuildInfo) Info

ResolveFrom reports a build from stamps and the build information embedded in it, which may be nil for a binary the toolchain recorded nothing about. A stamp that is set wins; what the build information says fills the rest.

func (Info) Report

func (i Info) Report(name string) string

Report is the version block a command prints for -version: name and version on the first line, the commit, build time and Go version aligned beneath.

type Stamps

type Stamps struct {
	Version   string
	Commit    string
	BuildTime string
	GoVersion string
}

Stamps are the values the linker's -X flags wrote into a main package's Version, Commit, BuildTime and GoVersion, or their defaults when a build passed none; the defaults, like an empty string, count as unset.

Jump to

Keyboard shortcuts

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