Last Updated: June 21, 2016
·
7.675K
· mtchavez

Golang Package Version Flag

Here is an example of how to implement a version flag for a go program or binary. Taken from my post with more description here

package main

import (
    "flag"
    "fmt"
    "os"
)

const AppVersion = "1.0.0 beta"

func main() {
    version := flag.Bool("v", false, "prints current roxy version")
    flag.Parse()
    if *version {
      fmt.Println(AppVersion)
      os.Exit(0)
    }
    fmt.Println("Hello from main()")
}