configor
configor copied to clipboard
default not supported in slice and map
Reproducible Example
type Config struct {
Foo struct {
Servers []struct {
Name string
Port int
Host string `default:"0.0.0.0"`
}
Testing map[string]struct {
Name string `default:"default"`
}
}
}
foo:
servers:
- name: dev
port: 4000
- name: alpha
port: 5000
testing:
data1:
Description
The field in slice and map won't get default value when empty.
The default values are applied before the config is loaded. So the later loaded structs in the slice don't have default values.
https://github.com/jinzhu/configor/blob/1095c485b440be00e1ddf075f4acdbebc3d6e97e/utils.go#L375-L391