version

package module
v1.0.4 Latest Latest
Warning

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

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

README

version

Reusable wrappers/utils to extract version(s) from golang Buildinfo included in go installed binaries

import fortio.org/version

var shortVersion, longVersion, fullVersion := version.FromBuildInfo()

Complete example in sample/simpleMain.go

See also a tiny library using this one to reduce the repition in main programs: fortio.org/cli package.

Yielding:

$ go install fortio.org/version/sample@latest
go: downloading fortio.org/version v1.0.0
$ ~/go/bin/sample -h
fortio.org/version sample main 1.0.0 usage:
	/Users/dl/go/bin/sample [flags]
flags:
  -buildinfo
    	Show full build info and exit.
$ ~/go/bin/sample -buildinfo
1.0.0 h1:JbGoGiNQ0883KoVPDsYhQCQ32QkAVTtECn86XVRRYi4= go1.19.5 arm64 darwin
go	go1.19.5
path	fortio.org/version/sample
mod	fortio.org/version	v1.0.0	h1:JbGoGiNQ0883KoVPDsYhQCQ32QkAVTtECn86XVRRYi4=
build	-compiler=gc
build	CGO_ENABLED=1
build	CGO_CFLAGS=
build	CGO_CPPFLAGS=
build	CGO_CXXFLAGS=
build	CGO_LDFLAGS=
build	GOARCH=arm64
build	GOOS=darwin
$ ~/go/bin/sample
2023/02/12 13:34:37 fortio.org/version sample main started 1.0.0 h1:JbGoGiNQ0883KoVPDsYhQCQ32QkAVTtECn86XVRRYi4= go1.19.5 arm64 darwin

Libraries can embed their own version using for instance

func init() { //nolint:gochecknoinits // we do need an init for this
	shortVersion, longVersion, fullVersion = version.FromBuildInfoPath("fortio.org/fortio")
}

and the longVersion in this example can then show both the module/library version and the version of the containing binary. eg

fortio 1.40.0 h1:jSDO/jGcyC/qTpMZZ84EZbn9BQawsWM9/RMQ9s6Cn3w= go1.19.5 arm64 darwin (in fortio.org/fortiotel 1.3.0)

Documentation

Overview

Package version wraps golang BuildInfo for easy versioning of go binaries (installed or built through go install).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromBuildInfo

func FromBuildInfo() (short, long, full string)

FromBuildInfo can be called by other programs to get their version strings (short,long and full) automatically added by go 1.18+ when doing `go install project@vX.Y.Z` and is also used for fortio itself.

func FromBuildInfoPath

func FromBuildInfoPath(path string) (short, long, full string)

FromBuildInfoPath returns the version of as specific module if that module isn't already the main one. Used by Fortio library version init to remember it's own version. Can be used by any other library to extract their own running version. It will also indicate the containing binary's version if the module is not the main one.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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