From bbea9342330ff020b8e3094c849db88719915132 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 26 Dec 2020 12:54:42 +0100 Subject: Continued implementing config validation --- config/config.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'config/config.go') diff --git a/config/config.go b/config/config.go index fada1ea..1deaf04 100644 --- a/config/config.go +++ b/config/config.go @@ -17,38 +17,25 @@ type Config struct { } func (c *Config) validate() error { + // App if err := c.App.validate(); err != nil { return err } + // Menus if len(c.Menus) < 2 { return errors.New("A valid configuration needs at least two menu entries named anonymous and logged_in") } - found_anonymous_menu := false - found_logged_in_menu := false for k, v := range c.Menus { if err := v.validate(k); err != nil { return err } - if k == "anonymous" { - found_anonymous_menu = true - } - if k == "logged_in" { - found_logged_in_menu = true - } - } - if !found_anonymous_menu { - return errors.New("No anonymous menu declared") - } - if !found_logged_in_menu { - return errors.New("No logged_in menu declared") } + // Games for k, v := range c.Games { if err := v.validate(k); err != nil { return err } } - // TODO menu existence is tested in global config - // TODO game existence is tested in global config return nil } @@ -64,6 +51,14 @@ func LoadFile(path string) (config Config, err error) { if err = decoder.Decode(&config); err != nil { return } - err = config.validate() + if err = config.validate(); err != nil { + return + } + // If all looks good we validate menu consistency + for _, v := range config.Menus { + if err = v.validateConsistency(&config); err != nil { + return + } + } return } -- cgit v1.2.3