A simple Go package to manage version information in your CLI applications using build-time flags.
This package uses Go's -ldflags to inject version information at build time. The version is stored in a package-level
variable that can be set during compilation.
The GetVersion() function returns the version using this priority:
- Version set via
-ldflagsat build time - Version from
debug.ReadBuildInfo()(when using Go modules) "unknown-local"as fallback for local development
package main
import "github.com/dev-services42/version"
func main() {
fmt.Printf("Version: %s\n", version.GetVersion())
}Use -ldflags to set the version at build time:
go build -ldflags "-X github.com/dev-services42/version.version=v1.2.3"