buildinfo

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package buildinfo resolves the running binary's version and commit metadata using a layered fallback: ldflag-injected values > module pseudo-version > VCS settings embedded by Go 1.18+ > literal "dev".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	// Version is a human-readable version string. Possible shapes:
	//   "v1.2.3"           — release tag (ldflag or @v1.2.3 install)
	//   "abc1234"          — short SHA when no tag is available
	//   "abc1234 (2026-05-12)" — pseudo-version rendered from go install ...@latest
	//   "abc1234+dirty"    — built from a tree with uncommitted changes
	//   "dev"              — no metadata at all (go build -trimpath -buildvcs=false, etc.)
	Version string

	// Commit is the full or short SHA, or "unknown" if unavailable.
	Commit string

	// BuildTime is an ISO-8601 timestamp from ldflags or vcs.time, or "unknown".
	BuildTime string

	// Dirty is true when the binary was built from a working tree with
	// uncommitted edits. Callers should disable any "is my binary up to date"
	// comparison when Dirty is true — vcs.revision in that case is the parent
	// commit, not what's actually running.
	Dirty bool
}

Info is the resolved metadata for the running binary.

func FromBuildtime

func FromBuildtime(ldflagVersion, ldflagCommit, ldflagBuildTime string) Info

FromBuildtime resolves Info using the supplied ldflag values and the running binary's embedded debug.BuildInfo.

func Resolve

func Resolve(in Inputs) Info

Resolve applies the fallback chain to the given inputs.

type Inputs

type Inputs struct {
	LDFlagVersion   string
	LDFlagCommit    string
	LDFlagBuildTime string
	BuildInfo       *debug.BuildInfo
}

Inputs override the build-time globals. They exist so tests can construct arbitrary scenarios without touching package state.

Jump to

Keyboard shortcuts

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