buildinfo
Version, commit, build time and module info for Go binaries, from runtime/debug with -ldflags overrides.
go get github.com/ubgo/buildinfo
- Language
- Go
- Go version
- 1.24
- Core deps
- 0 direct
- Latest tag
- v0.1.2
- License
- Apache-2.0
- Go modules
- 9
How it fits together
Code from the README
package main
import (
"log"
"github.com/ubgo/buildinfo"
)
func main() {
info := buildinfo.Get()
log.Printf("starting %s commit=%s go=%s",
info.Version, info.Commit, info.GoVersion)
}info := buildinfo.Get()
log.Printf("starting %s (%s)", info.Version, info.Source)
if !info.HasVersion() {
log.Println("warning: unstamped build")
}// Auto-populated, cached after first call.
info := buildinfo.Get()
// Flat string-only map for simple renderers.
m := buildinfo.Map()
// JSON-marshalled bytes for HTTP / log payloads.
b, _ := info.JSON()From the buildinfo README.
At a glance (from the README)
Source | Meaning |
|---|---|
SourceLdflags | stamped at build time by the release pipeline |
SourceModule | resolved by go install <pkg>@<version> |
SourceUnknown | plain go build / go run / go test — Version is the DevVersion placeholder |