Add version info in your Go project
Here is a simple example to add version info in your go project.
Code
package main
import (
"flag"
"fmt"
"os"
)
var AppVersion string = "dev"
func main() {
Version := flag.Bool("v", false, "")
if *Version {
fmt.Println(AppVersion)
os.Exit(0)
}
}
Compile
go build -ldflags="-X 'main.AppVersion=v1.0.0'"
Test
./your-binary -v
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here