add key if not present

This commit is contained in:
2021-04-12 00:02:35 +02:00
parent 19e75c1dad
commit 03ca0c8677
5 changed files with 91 additions and 7 deletions

View File

@@ -2,7 +2,6 @@ package internal
import (
"fmt"
"log"
"path"
"strings"
"sync"
@@ -27,7 +26,7 @@ func GetConfig() *Config {
once.Do(func() {
config = &Config{}
if err := viper.UnmarshalExact(config); err != nil {
log.Fatal("Nope ", err)
panic(err)
}
})
}
@@ -45,15 +44,27 @@ func GetPathRelativeToConfig(p string) (string, error) {
}
}
func (c Config) CheckConfig() error {
func (c *Config) CheckConfig() error {
found := map[string]bool{}
for _, backend := range c.Backends {
if err := backend.validate(); err != nil {
return fmt.Errorf("backend \"%s\": %s", backend.Name, err)
return err
}
if _, ok := found[backend.Name]; ok {
return fmt.Errorf(`duplicate name for backends "%s"`, backend.Name)
} else {
found[backend.Name] = true
}
}
found = map[string]bool{}
for _, location := range c.Locations {
if err := location.validate(c); err != nil {
return fmt.Errorf("location \"%s\": %s", location.Name, err)
return err
}
if _, ok := found[location.Name]; ok {
return fmt.Errorf(`duplicate name for locations "%s"`, location.Name)
} else {
found[location.Name] = true
}
}
return nil