Documentation
¶
Overview ¶
Package versiongen provides an opinionated method to add version information (version number and git commit hash) to go projects via 'go generate'. It produces a go file that includes a vgVersion constant with the version of your software and a vgHash constant with the SHA1 of the HEAD at build time.
It assumes:
1. your go project uses git for source control
2. you have at least one tagged commit (e.g v0.1)
The file it creates (version.go by default) looks like:
package main
const (
vgVersion = "v0.1-2-g7665642+"
vgHash = "7665642a17cecca2693d48276b07c28bd29cda06"
vgClean = false
)
Look into the example subdirectory to see how you can use it:
git clone github.com/andmarios/go-versiongen cd go-versiongen/example ls go generate go run main.go version.go
Index ¶
Constants ¶
const ( DefaultDirtyString = "+" DefaultTimeout = 15 * time.Second )
Variables ¶
var DirtyString = DefaultDirtyString
DirtyString is a string appended to the vgVersion constant if you have uncommited changes in your current code. Default is "+".
var IgnoreFiles = []string{"version.go"}
IgnoreFiles is an array of filenames that versiongen should ignore when trying to detect uncommited changes. By default it contains only "version.go" which if it is the only file changed doesn't affect the runtime behaviour of your software.
var Timeout = DefaultTimeout
Timeout is of type time.Duration and is the amount of time versiongen will wait for each git command it runs to complete before killing it. Default is 15 * time.Second.
Functions ¶
func Create ¶
func Create() error
Create will create a file named version.go in the directory you ran 'go generate', that will contain two constants:
vgVersion: The version of your program as given by 'git describe --tags' plus the DirtyString variable if you have uncommited changes.
vgHash: The SHA1 hash of your current commit.
func CreateFile ¶
CreateFile will work as Create() but instead of writing version.go in the directory you ran 'go generate' in, it will write filename instead (which may include a path).
Types ¶
This section is empty.