Viper: Defaults inside tags, similar to mapstructure

Created on 8 Nov 2016  路  1Comment  路  Source: spf13/viper

At the moment, it's possible to define a set of types, annotated with mapstructure tags, like so:

type OtherConfig struct {
  X string `mapstructure:"x-value"`
}

type Config struct {
  Host  string       `mapstructure:"host"`
  Other *OtherConfig `mapstructure:"other"`
}

Then we can just run:

var c *Config

viper.ReadInConfig()
viper.Unmarshal(&c)

And it will just work. But setting the default values will break this clean format... It would be really nice to add default values inside the tags like:

type OtherConfig {
  X string `mapstructure:"x-value" viperdefault:"I'm a default string"`
}

Most helpful comment

I agree with this.
It's why I'm not sure whether to use viper or another configuration library.

>All comments

I agree with this.
It's why I'm not sure whether to use viper or another configuration library.

Was this page helpful?
0 / 5 - 0 ratings