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
4
viper.go
4
viper.go
|
@ -1462,9 +1462,13 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
|
|||
|
||||
switch strings.ToLower(v.getConfigType()) {
|
||||
case "yaml", "yml":
|
||||
// Try UnmarshalStrict first, so we can warn about duplicated keys
|
||||
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":
|
||||
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue