Created
June 16, 2016 21:18
-
-
Save abraithwaite/500c1aa708c4d0880b40b79deabfd30a to your computer and use it in GitHub Desktop.
Idea to use define common flags in go libraries.
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" | |
) | |
type Config struct { | |
A *string | |
B *int | |
C *bool | |
} | |
func Flags() Config { | |
a := flag.String("a", "default", "a") | |
b := flag.Int("b", 0, "a") | |
c := flag.Bool("c", false, "asdf") | |
return Config{ | |
A: a, | |
B: b, | |
C: c, | |
} | |
} | |
func main() { | |
d := Flags() | |
flag.Parse() | |
fmt.Println(*d.A) | |
fmt.Println(*d.B) | |
fmt.Println(*d.C) | |
} |
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
14:15:45 $ go run flags_pattern.go -a=asdf -b=32 -c | |
asdf | |
32 | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment