buildinfo

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package buildinfo provides build metadata for Spirit binaries.

It supports two sources of build information:

  1. Compile-time injection via -ldflags (preferred for release binaries)
  2. runtime/debug.ReadBuildInfo() VCS settings (automatic for dev builds from a git checkout)

The Set() function should be called from main() with the ldflags-injected variables. Get() returns the resolved build info, preferring ldflags values when available and falling back to debug.ReadBuildInfo().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(version, commit, date string)

Set stores the compile-time injected values from -ldflags. Call this once from main() before any call to Get().

Example ldflags:

go build -ldflags "-X main.version=v1.2.3 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"

Types

type Info

type Info struct {
	Version  string // version (e.g. "v1.2.3"), or "dev"
	Commit   string // full git commit hash, or "unknown"
	Date     string // build date in RFC3339, or "unknown"
	Modified bool   // true if the working tree had uncommitted changes
	GoVer    string // Go version used for the build
}

Info holds the resolved build metadata.

func Get

func Get() Info

Get returns the resolved build info. It prefers ldflags-injected values and falls back to runtime/debug.ReadBuildInfo() VCS settings. The result is computed once and cached.

type VersionFlag

type VersionFlag bool

VersionFlag is a Kong-compatible flag that prints detailed build info and exits.

func (VersionFlag) BeforeReset

func (v VersionFlag) BeforeReset(app *kong.Kong, vars kong.Vars) error

BeforeReset is called by Kong before argument parsing when --version is passed. It prints the full build info and exits with code 0.

Jump to

Keyboard shortcuts

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