buildinfo

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: Apache-2.0 Imports: 2 Imported by: 10 modules, 1 package

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 provides functions for setting build information for CLIs and programs. Since CLIs and programs can be compiled, downloaded as a binary, or installed via `go install`, there's some nuanced logic in getting these values correct across all instances.

Consumers are encouraged to create an internal package in their module at "internal/version" with the following contents:

var (
  Name = "my-program"

  Version = buildinfo.Version()

  Commit = buildinfo.Commit()

  OSArch = buildinfo.OSArch()

  HumanVersion = Name + " " + Version + " (" + Commit + ", " + OSArch + ")"
)

These variables can then be referenced throughout the program. The values can still be overridden with LDFLAGS (which will take precedent over any values defined here).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit() string

Commit returns the VCS information, specifically the revision. Since most of our modules use Git, this is the Git SHA. If no SHA exists (e.g. outside of a repo), it returns "HEAD".

func OSArch

func OSArch() string

OSArch returns the denormalized operating system and architecture, separated by a slash (e.g. "linux/amd64").

func Version

func Version() string

Version attempts to read the module version injected by the compiler. If no information is present, it returns "source".

Types

This section is empty.

Jump to

Keyboard shortcuts

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