1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 16:49:42 +00:00

Add check for dupliate ID or alias

This commit is contained in:
Emma 2018-10-02 13:17:03 -06:00
parent 9ebdf41400
commit 9d283e36f6

View file

@ -1,6 +1,7 @@
package main
import (
"errors"
"io/ioutil"
"gopkg.in/yaml.v2"
@ -36,5 +37,21 @@ func LoadConfig(path string) (*Config, error) {
var config Config
yaml.Unmarshal(data, &config)
ids := make(map[string]bool)
aliases := make(map[string]bool)
for _, v := range config.Sensors {
if !ids[v.ID] {
ids[v.ID] = true
} else {
return nil, errors.New("Duplicate sensor ID found in configuration")
}
if !aliases[v.Alias] {
aliases[v.Alias] = true
} else {
return nil, errors.New("Duplicate sensor alias found in configuration")
}
}
return &config, nil
}