Last active
December 22, 2022 08:09
-
-
Save maqiv/00ca87bfe146ddc7c8840b23bcbfa5f7 to your computer and use it in GitHub Desktop.
Parsing flags into variables/structs in golang
This file contains hidden or 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
| /* | |
| Call this example as follows: | |
| $ go run flag_muh.go -muh=blahmuh -blh=muhblah | |
| {blahmuh muhblah} | |
| */ | |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| ) | |
| type Muh struct { | |
| Eins string | |
| Zwei string | |
| } | |
| func main() { | |
| m := new(Muh) | |
| flag.StringVar(&m.Eins, "muh", "hallo", "h") | |
| flag.StringVar(&m.Zwei, "blh", "welt", "w") | |
| flag.Parse() | |
| fmt.Print(*m) | |
| } |
abdennour
commented
Nov 17, 2021
fmt.Printf("%+v\n", *s)
Man, you dig deep down into my past 😆
Thanks for your suggestion!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment