I have a viper config that has some fixed fields, and some dynamic fields. It looks like this:
//always contains those keys
a: 1
b: "2"
c: true
//those keys might change:
params:
x1: 111
x2: "222"
I know I can unmarshal the params
part into a map[string]interface{}
and use the values at runtime, but I would like to unmarshal this config into the a viper config instead, ie the struct should look like this:
type Config struct {
A int `mapstructure:"a"`
B string `mapstructure:"b"`
C bool `mapstructure:"c"`
Params viper.Viper `mapstructure:"params"`
}
but when trying to use the struct like that, the Params
variable is unmarshaled into an empty config.
Can viper support such usage?