template/internal/buildinfo/buildinfo.go
djmil 4f55fcbef5 build stamping
- store build metadata (version, commit, date)
- multi-binary build: `make build` builds all packages from ./cmd
- devcontainer adds ./bin to the PATH by default
2026-06-13 20:32:24 +00:00

26 lines
992 B
Go

// Package buildinfo exposes build-time metadata injected via -ldflags.
// All vars default to safe fallbacks so the binary runs without stamping.
//
// Wire into the binary by passing LDFLAGS from the Makefile:
//
// go build -ldflags "-X .../internal/buildinfo.Commit=$(git rev-parse --short HEAD) \
// -X .../internal/buildinfo.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
// -X .../internal/buildinfo.Version=$(git describe --tags)"
package buildinfo
import "fmt"
// Version is the semver release tag (e.g. "v1.2.3") or "dev" for untagged builds.
var Version = "dev"
// Commit is the short git SHA of the build (e.g. "a1b2c3d").
var Commit = "unknown"
// BuildTime is the UTC timestamp when the binary was compiled (RFC 3339).
var BuildTime = "unknown"
// String returns a one-line summary suitable for a --version flag or startup log line.
func String() string {
return fmt.Sprintf("version=%s commit=%s built=%s", Version, Commit, BuildTime)
}