version

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

version holds various strings describing the current version of a program. The intention is that the values are set through the -ldflags argument to the go build and go install tools as follows:

PKG=github.com/nickwells/version.mod/version
go build -ldflags="-X '$PKG.tag=v1.2.3' ..."

The values that can be set are:

tag
commit
author
date
buildUser
buildDate

Each of these values is a string.

A suggested way of setting each of these values when using git on a Linux platform is as follows:

first set up a shell variable to hold the date format to avoid retyping

DATEFMT="%Y/%m/%d %H:%M:%S"

tag=$(git --no-pager tag --contains=HEAD)
commit=$(git rev-parse HEAD)
author=$(git --no-pager log -1 --format='%an')
date=$(git --no-pager log -1 --date="format:$DATEFMT" --format='%cd')
buildUser=$(id --user --real --name)
buildDate=$(date "+$DATEFMT")

Add these values after the package name as shown above with the -ldflags parameter to go build or go install.

There is a shell script available (see _sh/goBuildLdflags) which will construct these arguments for you.

If you wish to build the program without the checks that the build values have been set then build the program with the build tag version_no_check set as follows:

go build -tags version_no_check

Without this build tag a program built without any version information having been set will panic at startup.

Deprecated: this package is superseded by the information in runtime/debug. It is error-prone, depending as it does on the need for complex build-time parameters to be set up. It is no longer needed as some of the features it offered are now provided automatically by the runtime through the runtime/debug.BuildInfo type. The go version command also provides access to the same information for binaries compiled with Go versions since go1.18

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All deprecated

func All() string

All returns a string giving all the version details. It is a formatted string with the values shown following names.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func Author deprecated

func Author() string

Author returns the author of the latest commit.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func BuildDate deprecated

func BuildDate() string

BuildDate returns the date that the program was built.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func BuildUser deprecated

func BuildUser() string

BuildUser returns the user that built the program.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func Commit deprecated

func Commit() string

Commit returns the latest commit ID.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func Date deprecated

func Date() string

Date returns the date of the latest commit.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

func Tag deprecated

func Tag() string

Tag returns the version tag. If semantic versioning is being followed this should be of the form: vx.y.z where x, y and z are numbers.

Deprecated: this package is no longer supported as much of the necessary information is now provided by the Go runtime/debug package through the BuildInfo type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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