Created
August 21, 2014 10:27
-
-
Save andreagrandi/c7ad4307ee61812084ac to your computer and use it in GitHub Desktop.
Parse command line flags in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Example: go run cmd_flag_parser.go -host example.com -port 3000