config: fix default fallback

This commit is contained in:
Jimmy Zelinskie 2016-03-17 14:52:41 -04:00
parent 19b730ea67
commit 20af787437

View File

@ -66,7 +66,8 @@ type APIConfig struct {
}
// DefaultConfig is a configuration that can be used as a fallback value.
var DefaultConfig = Config{
func DefaultConfig() Config {
return Config{
Database: &DatabaseConfig{
CacheSize: 16384,
},
@ -82,12 +83,14 @@ var DefaultConfig = Config{
Attempts: 5,
RenotifyInterval: 2 * time.Hour,
},
}
}
// Load is a shortcut to open a file, read it, and generate a Config.
// It supports relative and absolute paths. Given "", it returns DefaultConfig.
func Load(path string) (config *Config, err error) {
config = &DefaultConfig
var cfgFile File
cfgFile.Clair = DefaultConfig()
if path == "" {
return
}
@ -103,7 +106,6 @@ func Load(path string) (config *Config, err error) {
return
}
var cfgFile File
err = yaml.Unmarshal(d, &cfgFile)
if err != nil {
return