Closed tchap closed 7 years ago
I'd recommend against that approach -- it's starting to turn struct field tags into a mini DSL. A tiny bit of code wrapping the envconfig.Process
could handle this for you. Logic like "try this env var, then fallback here" is getting a little involved for envconfig to tackle directly.
Right. I will think about your advice. Thanks!
Hi,
I am embedding one config struct in another. The embedded struct is used across multiple projects. What I would need is to be able to set different default values based on the project, which is not possible since the tag value is static.
An example could be that I would like to use the value of
SERVICE_NAME
environment variable in the embedded config struct as the default value for something.I am probably going to fork this package and implement it so that when there is
default:"$SERVICE_NAME"
, the relevant environment variable is used as the default value. I am just wondering whether to send a PR afterwards. Does it seem handy for other people?Or perhaps you want to implement it yourself quickly. It's just about checking whether
default
starts with$
or any other magical prefix and act accordingly...Cheers!