2025/06/19
That go’s runtime/debug package keeps track of the version of all modules:
package main
import (
"fmt"
"runtime/debug"
)
func main() {
info, _ := debug.ReadBuildInfo()
fmt.Printf("info: %#v", info)
}
// info: &debug.BuildInfo{
// GoVersion: "go1.24.4",
// Path: "play",
// Main:debug.Module{
// Path:"play",
// Version:"(devel)",
// Sum:"",
// Replace:(*debug.Module)(nil),
// },
// Deps:[]*debug.Module(nil),
// Settings:[]debug.BuildSetting{
// debug.BuildSetting{Key:"-buildmode", Value:"exe"},
// debug.BuildSetting{Key:"-compiler", Value:"gc"},
// debug.BuildSetting{Key:"-tags", Value:"faketime"},
// debug.BuildSetting{Key:"CGO_ENABLED", Value:"0"},
// debug.BuildSetting{Key:"GOARCH", Value:"amd64"},
// debug.BuildSetting{Key:"GOOS", Value:"linux"},
// debug.BuildSetting{Key:"GOAMD64", Value:"v1"}}}
https://go.dev/play/p/RPP3ld4kPmD
See also https://pkg.go.dev/runtime/debug#BuildInfo
I heard about this from https://github.com/charmbracelet/fang#:~:text=automatic%20--version%3A%20set%20it%20to%20the%20build%20info%2C%20or%20a%20version%20of%20your%20choice