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:
parent
9ebdf41400
commit
9d283e36f6
1 changed files with 17 additions and 0 deletions
17
config.go
17
config.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue