buildinfo

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

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