buildinfo

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: AGPL-3.0 Imports: 4 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 and formats canonical build identity metadata for WindShare Go binaries, matching the release and commit contract used by wsrelay.

Index

Constants

View Source
const (
	// LinkerPackage is the Go import path that owns the -ldflags -X stamp symbols.
	LinkerPackage = "github.com/windshare/windshare/internal/buildinfo"
	// CommitHexLength is the exact length of a canonical lowercase Git SHA-1.
	CommitHexLength = 40
	// MaxReleaseLength bounds canonical semantic release tags (vX.Y.Z).
	MaxReleaseLength = 64
	// UnstampedLabel is displayed when a binary has neither linker-stamped nor
	// embedded Git VCS identity.
	UnstampedLabel = "unstamped"
)

Variables

View Source
var (
	// ErrInvalidCommit reports a missing or malformed 40-character lowercase hex SHA.
	ErrInvalidCommit = errors.New("build commit must be a 40-character lowercase hex SHA")
	// ErrInvalidRelease reports a non-canonical release tag.
	ErrInvalidRelease = errors.New("build release must have the form vX.Y.Z without leading zeroes")
	// ErrDirtyRelease reports an attempt to stamp a release build as dirty.
	ErrDirtyRelease = errors.New("release build cannot be marked dirty")
	// ErrInvalidDirty reports an unrecognized dirty flag spelling.
	ErrInvalidDirty = errors.New("build dirty flag must be true, false, 1, or 0")
)

Functions

func IsValidCommit

func IsValidCommit(value string) bool

IsValidCommit reports whether value is a 40-character lowercase hex SHA.

func IsValidRelease

func IsValidRelease(value string) bool

IsValidRelease reports whether value is a canonical vX.Y.Z release tag without leading zeroes, prerelease/build suffixes, or uint64 overflow.

Types

type Explicit

type Explicit struct {
	Release string
	Commit  string
	Dirty   string
}

Explicit holds raw linker-stamped build identity strings.

type Info

type Info struct {
	// contains filtered or unexported fields
}

Info represents a validated binary build identity.

Release builds always carry both a canonical vX.Y.Z tag and a 40-character lowercase Git SHA and are never dirty. Revision builds carry a commit SHA and a dirty bit. Unstamped builds carry neither.

func Current

func Current() Info

Current resolves the running binary's build identity, preferring explicit linker stamps over Go's embedded VCS metadata.

func FromBuildInfo

func FromBuildInfo(bi *debug.BuildInfo) Info

FromBuildInfo extracts a Git revision identity from Go's embedded BuildInfo.

func FromParts

func FromParts(releaseTag, commitSHA string, isDirty bool) (Info, error)

FromParts constructs a validated build identity from typed parts.

func ParseExplicit

func ParseExplicit(explicit Explicit) (Info, error)

ParseExplicit validates raw linker-stamped build strings.

func Resolve

func Resolve(explicit Explicit, bi *debug.BuildInfo) Info

Resolve computes the validated build identity from explicit linker values and Go's runtime/debug.BuildInfo.

When any explicit value is present, it takes full authority without falling back to ambient VCS metadata so a malformed explicit stamp never silently reports a different revision.

func (Info) Commit

func (info Info) Commit() string

Commit returns the 40-character lowercase Git SHA for stamped builds, or "".

func (Info) Dirty

func (info Info) Dirty() bool

Dirty reports whether a revision build had uncommitted changes.

func (Info) FormatLine

func (info Info) FormatLine(program string) string

FormatLine formats the CLI version line ("<program> <identity>").

func (Info) Kind

func (info Info) Kind() Kind

Kind returns the build identity classification.

func (Info) LDFlags

func (info Info) LDFlags() string

LDFlags formats the go build -ldflags -X argument that stamps this validated build identity into a binary, or "" for an unstamped Info.

func (Info) Release

func (info Info) Release() string

Release returns the canonical vX.Y.Z release tag for release builds, or "".

func (Info) Stamped

func (info Info) Stamped() bool

Stamped reports whether the binary carries a validated build identity.

func (Info) String

func (info Info) String() string

String formats the build identity without a program prefix.

type Kind

type Kind uint8

Kind distinguishes release, revision, and unstamped binaries.

const (
	KindUnstamped Kind = iota
	KindRevision
	KindRelease
)

Jump to

Keyboard shortcuts

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