configor icon indicating copy to clipboard operation
configor copied to clipboard

default not supported in slice and map

Open hulucc opened this issue 3 years ago • 1 comments

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.

hulucc avatar May 26 '21 08:05 hulucc

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

moycat avatar Jul 15 '21 13:07 moycat