Golang flag.Parse() function examples

package flag

Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.

Golang flag.Parse() function usage examples

Example 1:

 func main() {
 community := flag.String("community", "public", "community program")
 host := flag.String("host", "127.0.0.1", "host")
 flag.Parse()
 ...

Example 2:

 func main() {
 flag.Parse()

 if flag.NArg() != 1 {
  log.Fatal("filename not specified")
 }
 filename = flag.Args()[0]
 ....

Reference :

http://golang.org/pkg/flag/#Parse

Advertisement