fs := mflag.NewFlagSet("myflags", mflag.ExitOnError) addr := fs.String("addr", "", "Address to listen on") port := fs.Int("port", 80, "Port to listen on")
if err := fs.Parse(os.Args[1:]); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) }
fs.SetDefault("addr", "localhost") fs.SetDefault("port", 8080)This example sets the default values of "addr" and "port" flags to "localhost" and 8080 respectively. Overall, "github.com/docker/docker/pkg/mflag" is a useful package library for parsing command line arguments and defining flags in Go applications, especially for those using Docker.