version

package
v0.0.0-...-70044d4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

Version

Version package helps to automate process of versioning Go executables by using information from git repository and build environment and assigning them during compilation using -X importpath.name=value flag of go link tool.

Concatenated form

v0.6.3+35-dev-0788ff2 (2016/02/05-22:10) built on furby@beast (go1.5.1 linux-amd64) at Sat Feb 06 09:52:22 UTC 2016

Assigned info

  • version.Number
    • the most recent annotated tag
    • if the last commit doesn't point to the tag, +N is added where N is number of commits since the tag
    • if the working tree is dirty, -dev is added
  • version.CommitHash
    • 7 hexadecimal digits representing abbreviated object name
  • version.CommitStamp
    • time of the last commit
  • version.BuildUser
    • user that built the executable
  • version.BuildHost
    • host that the executable was built on
  • version.BuildStamp
    • time of building the executable
  • version.Long
    • all information concatenated into long form

Quick start

  1. Run go get -u github.com/TrueFurby/version to download this package.
  2. In the directory of your main package, run ln -s $GOPATH/src/github.com/TrueFurby/version to create a symlink to the version package. This will provide cleaner way for importing and compiling.
  3. Use go build -ldflags "$(sh version/ldflags.sh)" when building your executable to assign all version information.
  4. Now you can simply refer to the exported variables which will contain assigned information wherever you need them.

Usage example

package main

import "yourproject/version"

func main() {
    printVersion = flag.Bool("version", false, "print version")
    flag.Parse()
    
    if *printVersion {
        fmt.Println(version.Long)
        os.Exit(0)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Number      = "<undefined>"
	CommitHash  = "<undefined>"
	CommitStamp = "<undefined>"
	BuildUser   = "<undefined>"
	BuildHost   = "<undefined>"
	BuildStamp  = "<undefined>"

	Long string
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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