l8xlka
Last Updated: June 21, 2016
·
3.253K
· mtchavez
Chavez cartoon head

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()")
}
Say Thanks
Respond