You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know Unmarshal exists but it doesn't do what i was expecting. My expectation for the above snippet was that, after the Unmarshal call, following would be true:
cfg.Host would be mapped to HOST env var, or host key in app.yaml or app.json etc.
cfg.Database.Host would be mapped to DATABASE_HOST env var, database_host key in app.yaml or app.json etc (or host sub-key of database key in these files)
Non-zero values given to the fields will be used as defaults if an overriding value not found in any config source (i.e., env var, yaml files, json files etc.)
Why?
One of the projects i am working which is using viper has has large set of configuration options. It is becoming tedious to add viper.GetString("config_name") for every single config and then populate the config struct. If the above expectations were true, we could simply compose configs of different structs into one config struct and call Unmarshal with that struct.
The text was updated successfully, but these errors were encountered:
Is there a way to directly register a
struct
with viper and read configs appropriately ?Something like demonstrated below:
I know
Unmarshal
exists but it doesn't do what i was expecting. My expectation for the above snippet was that, after theUnmarshal
call, following would be true:cfg.Host
would be mapped toHOST
env var, orhost
key inapp.yaml
orapp.json
etc.cfg.Database.Host
would be mapped toDATABASE_HOST
env var,database_host
key inapp.yaml
orapp.json
etc (orhost
sub-key ofdatabase
key in these files)Why?
One of the projects i am working which is using
viper
has has large set of configuration options. It is becoming tedious to addviper.GetString("config_name")
for every single config and then populate the config struct. If the above expectations were true, we could simply compose configs of different structs into oneconfig
struct and callUnmarshal
with that struct.The text was updated successfully, but these errors were encountered: