Created
January 24, 2017 22:13
-
-
Save abraithwaite/82dc09189d4bf45f9021017cc29c76fe to your computer and use it in GitHub Desktop.
flags dragons
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 ( | |
"fmt" | |
"flag" | |
) | |
var ( | |
flagName = flag.String("name", "default", "myname") | |
flagPlace = flag.String("place", "france", "myname") | |
flagNumber = flag.Int("number", 1, "myname") | |
) | |
func main() { | |
x := flags() | |
fmt.Println(x) | |
flag.Parse() | |
fmt.Println(x) | |
x = flags() | |
fmt.Println(x) | |
} | |
type Conf struct { | |
Name string | |
Place string | |
Number int | |
} | |
func flags() *Conf { | |
conf := &Conf { | |
Name: *flagName, | |
Place: *flagPlace, | |
Number: *flagNumber, | |
} | |
return conf | |
} |
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
abraithwaite at alan-mbpr in ~ | |
14:11:00 $ go run /tmp/play.go -name alan -place sfo -number 5 | |
&{default france 1} | |
&{default france 1} | |
&{alan sfo 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment