Go has flag package which is cool, but then running app in docker and kubernetes etc. I always end up using environment variables and writing custom logic to parse both flags (for development) and env variables(for production). My proposal is to have standard package which can handle both flags and env variables. I saw there is already one package https://github.com/namsral/flag which is a fork of std flag + added env variables handling.
Also this can be a separate package on golang.org/x/... if you think it doesn't make sense to put it to std lib.
The standard library is all about providing the basic blocks which can be composed to build most programs. You already have the flag package and os.Getenv - could you clarify why that isn't enough?
For example, I'd imagine something like the snippet below would be close to what you're after:
var foo = flag.String("foo", os.Getenv("APP_FOO"), "...")
$ ./prog -foo=bar
$ APP_FOO=bar ./prog
Also see https://golang.org/doc/faq#x_in_std. I can imagine more powerful flag/config/env libraries, but they can always live outside of the standard library.
Just for reference, Viper already handles environment variables, command-line flags, and config files in all popular formats. Plus, it's about as standard a library as there is outside the standard library.
Thanks for answers
Most helpful comment
The standard library is all about providing the basic blocks which can be composed to build most programs. You already have the
flagpackage andos.Getenv- could you clarify why that isn't enough?For example, I'd imagine something like the snippet below would be close to what you're after:
Also see https://golang.org/doc/faq#x_in_std. I can imagine more powerful flag/config/env libraries, but they can always live outside of the standard library.