Skip to content

dev-services42/version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version for your CLI programs

A simple Go package to manage version information in your CLI applications using build-time flags.

How it works

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:

  1. Version set via -ldflags at build time
  2. Version from debug.ReadBuildInfo() (when using Go modules)
  3. "unknown-local" as fallback for local development

Usage

1. Import the package

package main

import "github.com/dev-services42/version"

func main() {
	fmt.Printf("Version: %s\n", version.GetVersion())
}

2. Build with version information

Use -ldflags to set the version at build time:

go build -ldflags "-X github.com/dev-services42/version.version=v1.2.3"

About

Useful library to add version to Golan projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages