buildinfo

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package buildinfo resolves what a running binary knows about itself.

Three sources, in precedence order: values stamped at release time by GoReleaser's ldflags, then the metadata the Go toolchain records in the binary, then nothing. The middle tier is what makes `go install` produce a version-stamped binary; before it existed, any build that was not GoReleaser's reported "dev".

The tiers are complementary rather than redundant. A module-proxy install (`go install ...@latest`) records a real module version but no VCS information; a local `go build` records the reverse. Neither is a superset of the other, so both are consulted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Version  string // e.g. "v0.7.0"; empty when unknown
	Revision string // full VCS revision; empty when unknown
	Time     string // RFC3339 build time; empty when unknown
	Modified bool   // built from a working tree with uncommitted changes
	Source   Source
}

Info is what a binary knows about itself. Every field is best-effort: an empty string means "not recorded", never "zero".

func Resolve

func Resolve(ldVersion, ldCommit, ldDate string) Info

Resolve determines the running binary's identity. The ld* arguments are the release-time stamped values; empty or sentinel values mean "not stamped".

func (Info) Known

func (i Info) Known() bool

Known reports whether a usable version string was resolved, rather than revision-only metadata or no recorded identity.

type Source

type Source int

Source records where the resolved information came from, so callers can tell an authoritative version from an inferred one.

const (
	// SourceUnknown means nothing usable was recorded. Callers must not
	// substitute a placeholder that could be mistaken for a real version.
	SourceUnknown Source = iota
	// SourceBuildInfo means the values came from the Go toolchain's own
	// build metadata.
	SourceBuildInfo
	// SourceLDFlags means the values were stamped in at release time.
	SourceLDFlags
)

Jump to

Keyboard shortcuts

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