The flag package supports creating your own flags that know how to unmarshal themselves from strings. However the process is quite complex, so unless you are planning on supporting many many incoming arguments, it might be simpler to hard code the values of gw1 and 2 yourself. Or as the type is always the same, therefore it’s values are always the same you can do something like this.
var gw customType
flag.StringVar(&gw.Value1, “a”, “default”, “a’s description”)
flag.Parse()
I didn’t explain this very well from the start. I’m working with Digital Ocean’s GO API, and the customType is actually DropletCreateRequest as defined here.
I created my variables of this type like (of which there are multiple of the same type):
So then I would create a droplet with command line flags, like program --n=myServerName? And if I wanted to create outside of the defaults, it would be program --n=myServerName --r=nyc2 --i=ubuntu-14-04-x64 etc?
I like it
The only caveat I see here, are long commands that will eventually be wrapped in shell scripts for fast calling, but honestly, that’s probably better than having the droplet specs baked into the program itself.
My original plan was to source static json files as arguments, but that will be down the line.