earthboundkid / versioninfo

Importable package that parses version info from debug.ReadBuildInfo().

Home Page:https://blog.carlmjohnson.net/post/2023/golang-git-hash-how-to/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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")
}

About

Importable package that parses version info from debug.ReadBuildInfo().

https://blog.carlmjohnson.net/post/2023/golang-git-hash-how-to/

License:MIT License


Languages

Language:Go 100.0%