Skip to content

Instantly share code, notes, and snippets.

@mieitza
Forked from andreagrandi/cmd_flag_parser.go
Created November 1, 2015 19:33
Show Gist options
  • Save mieitza/11d355d69e1eb5d79084 to your computer and use it in GitHub Desktop.
Save mieitza/11d355d69e1eb5d79084 to your computer and use it in GitHub Desktop.
Parse command line flags in Go
package main
import (
"flag"
"fmt"
)
var hostName = flag.String("host", "localhost", "Hostname or IP you want to run this service on")
var portNumber = flag.Int("port", 8080, "Port you want this service to listen on (default 8080)")
func main() {
flag.Parse()
fmt.Println(*hostName)
fmt.Println(*portNumber)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment