Skip to content

Instantly share code, notes, and snippets.

@maqiv
Last active December 22, 2022 08:09
Show Gist options
  • Save maqiv/00ca87bfe146ddc7c8840b23bcbfa5f7 to your computer and use it in GitHub Desktop.
Save maqiv/00ca87bfe146ddc7c8840b23bcbfa5f7 to your computer and use it in GitHub Desktop.
Parsing flags into variables/structs in golang
/*
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
Copy link

fmt.Printf("%+v\n", *s)

@maqiv
Copy link
Author

maqiv 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