diff --git a/config_examples/configuration/defaults/service.yaml b/config_examples/configuration/defaults/service.yaml index aa0b950..4ae257c 100644 --- a/config_examples/configuration/defaults/service.yaml +++ b/config_examples/configuration/defaults/service.yaml @@ -4,4 +4,5 @@ defaults: level: "warn" format: "json" host: "127.0.0.1" - port: "8888" \ No newline at end of file + port: "8888" + string_value: string \ No newline at end of file diff --git a/config_examples/configuration/dev/service.yaml b/config_examples/configuration/dev/service.yaml index 014f618..619f64b 100644 --- a/config_examples/configuration/dev/service.yaml +++ b/config_examples/configuration/dev/service.yaml @@ -1,2 +1,3 @@ dev: - debug: true \ No newline at end of file + debug: true + string_value: null \ No newline at end of file diff --git a/go.mod b/go.mod index adc4f04..9e83385 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/spacetab-io/configuration-go go 1.14 require ( - github.com/imdario/mergo v0.3.9 + github.com/imdario/mergo v0.3.10-0.20200517151347-9080aaff8536 github.com/stretchr/testify v1.5.1 gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 11503c5..0e77cec 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg= -github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.10-0.20200517151347-9080aaff8536 h1:X5Ang7dBiLOoIANjgXiArEGrPWSjFQdaUjtsV9+gC5I= +github.com/imdario/mergo v0.3.10-0.20200517151347-9080aaff8536/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/reader.go b/reader.go index 95d3ddb..48adf01 100644 --- a/reader.go +++ b/reader.go @@ -88,7 +88,7 @@ func ReadConfigs(cfgPath string) ([]byte, error) { } cc := configs[folder] - _ = mergo.Merge(&cc, configFromFile[folder], mergo.WithOverride) + _ = mergo.Merge(&cc, configFromFile[folder], mergo.WithOverwriteWithEmptyValue) configs[folder] = cc @@ -101,7 +101,7 @@ func ReadConfigs(cfgPath string) ([]byte, error) { config := configs[defaultStage] if c, ok := configs[stage]; ok { - if err := mergo.Merge(&config, c, mergo.WithOverride); err == nil { + if err := mergo.Merge(&config, c, mergo.WithOverwriteWithEmptyValue); err == nil { iSay("Stage `%s` config is loaded and merged with `defaults`", stage) } } diff --git a/reader_test.go b/reader_test.go index c4e65ea..e1826e4 100644 --- a/reader_test.go +++ b/reader_test.go @@ -22,8 +22,9 @@ func TestReadConfigs(t *testing.T) { Level string `yaml:"level"` Format string `yaml:"format"` } `yaml:"log"` - Host string `yaml:"host"` - Port string `yaml:"port"` + Host string `yaml:"host"` + Port string `yaml:"port"` + StringValue string `yaml:"string_value"` } config := &cfg{} @@ -38,8 +39,9 @@ func TestReadConfigs(t *testing.T) { Level string `yaml:"level"` Format string `yaml:"format"` }{Level: "error", Format: "text"}, - Host: "127.0.0.1", - Port: "8888", + Host: "127.0.0.1", + Port: "8888", + StringValue: "", } assert.EqualValues(t, refConfig, config)