goversionflag is an go package aiming to help identifying versions of deployed go binarys.
go get -u github.com/stockholmuniversity/goversionflag
package main
import (
"fmt"
"github.com/stockholmuniversity/goversionflag"
)
func main() {
goversionflag.PrintVersionAndExit()
fmt.Println("End of program, will not be shown when run with '-version'")
}
When building your program with goversionflag you must add buildflags in the build process:
go build -ldflags "-X github.com/stockholmuniversity/goversionflag.projectName=$project -X github.com/stockholmuniversity/goversionflag.gitCommit=$commit -X github.com/stockholmuniversity/goversionflag.buildTime=$time"
If you are using a vendoring system, for example dep that puts all dependency's in an vendoring directory you must use the full path name relative to $GOPATH as described in issue
go build -ldflags "-X ${MYPROJECT}/vendor/github.com/stockholmuniversity/goversionflag.projectName=$project -X ${MYPROJECT}/vendor/github.com/stockholmuniversity/goversionflag.gitCommit=$commit -X ${MYPROJECT}/vendor/github.com/stockholmuniversity/goversionflag.buildTime=$time"
For more information see documentation and comments in printVersion.go and godoc: https://godoc.org/github.com/stockholmuniversity/goversionflag