Skip to content

Instantly share code, notes, and snippets.

@abraithwaite
Created June 16, 2016 21:18
Show Gist options
  • Save abraithwaite/500c1aa708c4d0880b40b79deabfd30a to your computer and use it in GitHub Desktop.
Save abraithwaite/500c1aa708c4d0880b40b79deabfd30a to your computer and use it in GitHub Desktop.
Idea to use define common flags in go libraries.
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)
}
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