Categorygithub.com/carlmjohnson/versioninfo
modulepackage
0.22.5
Repository: https://github.com/carlmjohnson/versioninfo.git
Documentation: pkg.go.dev

# README

versioninfo GoDoc Go Report Card

Importable package that parses debug.ReadBuildInfo() for inclusion in your Go application.

Requires Go 1.18+ for Git revision information, but compatible with prior versions of Go.

Examples

package main

import (
    "fmt"

    "github.com/carlmjohnson/versioninfo"
)

func main() {
    fmt.Println("Version:", versioninfo.Version)
    fmt.Println("Revision:", versioninfo.Revision)
    fmt.Println("DirtyBuild:", versioninfo.DirtyBuild)
    fmt.Println("LastCommit:", versioninfo.LastCommit)
}

You may use the concatenated information provided by versioninfo.Short():

package main

import (
    "fmt"

    "github.com/carlmjohnson/versioninfo"
)

func main() {
    fmt.Println("ShortInfo:", versioninfo.Short())
}

Add the -v and -version flags:

package main

import (
    "flag"
    "fmt"

    "github.com/carlmjohnson/versioninfo"
)

func main() {
    versioninfo.AddFlag(nil)
    flag.Parse()
    fmt.Println("done")
}

# Functions

AddFlag adds -v and -version flags to the FlagSet.
Short provides a short string summarizing available version information.

# Variables

DirtyBuild is taken from the vcs.modified tag in Go 1.18+.
LastCommit is taken from the vcs.time tag in Go 1.18+.
Revision is taken from the vcs.revision tag in Go 1.18+.
Version will be the version tag if the binary is built with "go install url/tool@version".