diff --git a/cmds/houndd/main.go b/cmds/houndd/main.go index 79e7f131..53b265b1 100644 --- a/cmds/houndd/main.go +++ b/cmds/houndd/main.go @@ -143,14 +143,14 @@ func main() { } var cfg config.Config - if err := cfg.LoadFromFile(*flagConf); err != nil { + if err := cfg.LoadFromFile(*flagConf, *flagCheckConf); err != nil { panic(err) } - if *flagCheckConf { - return - } - + if *flagCheckConf { + return + } + // Start the web server on a background routine. ws := web.Start(&cfg, *flagAddr, *flagDev) diff --git a/config/config.go b/config/config.go index c978c009..9f714def 100644 --- a/config/config.go +++ b/config/config.go @@ -188,14 +188,19 @@ func mergeVCSConfigs(cfg *Config) error { return nil } -func (c *Config) LoadFromFile(filename string) error { +func (c *Config) LoadFromFile(filename string, disallowUnknownFields bool) error { r, err := os.Open(filename) if err != nil { return err } defer r.Close() - if err := json.NewDecoder(r).Decode(c); err != nil { + decoder := json.NewDecoder(r) + if disallowUnknownFields { + decoder.DisallowUnknownFields() + } + + if err := decoder.Decode(c); err != nil { return err } diff --git a/config/config_test.go b/config/config_test.go index 5b3328af..dd788e0f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -20,7 +20,7 @@ func rootDir() string { // add examples, we don't muck them up. func TestExampleConfigsAreValid(t *testing.T) { var cfg Config - if err := cfg.LoadFromFile(filepath.Join(rootDir(), exampleConfigFile)); err != nil { + if err := cfg.LoadFromFile(filepath.Join(rootDir(), exampleConfigFile), true); err != nil { t.Fatalf("Unable to parse %s: %s", exampleConfigFile, err) }