mirror of
https://github.com/spf13/viper
synced 2025-05-06 04:07:17 +00:00
Merge pull request #5 from DataDog/albertvaka/warn-duplicate-keys-no-rebased
Warn when a yaml file has duplicated keys
This commit is contained in:
commit
991b92b30e
1 changed files with 6 additions and 2 deletions
8
viper.go
8
viper.go
|
@ -1462,8 +1462,12 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
|
||||||
|
|
||||||
switch strings.ToLower(v.getConfigType()) {
|
switch strings.ToLower(v.getConfigType()) {
|
||||||
case "yaml", "yml":
|
case "yaml", "yml":
|
||||||
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
|
// Try UnmarshalStrict first, so we can warn about duplicated keys
|
||||||
return ConfigParseError{err}
|
if strictErr := yaml.UnmarshalStrict(buf.Bytes(), &c); strictErr != nil {
|
||||||
|
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
|
||||||
|
return ConfigParseError{err}
|
||||||
|
}
|
||||||
|
log.Printf("warning reading config file: %v\n", strictErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "json":
|
case "json":
|
||||||
|
|
Loading…
Add table
Reference in a new issue