Skip to content

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
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App