From 484734ab36b06a9e6d35348e357312d99522302c Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 23 Dec 2020 12:01:05 +0100 Subject: Implemented the configuration file format --- config/config.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 config/config.go (limited to 'config/config.go') diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..2c94dbe --- /dev/null +++ b/config/config.go @@ -0,0 +1,31 @@ +package config + +import ( + "os" + + "gopkg.in/yaml.v2" +) + +type Config struct { + // AppConfig is the application level configuration entries + App App `yaml:"App"` + // Menus is the list of menus. The first one is the default menu for an anonymous user, the second one is the default menu for an authenticated user + Menus []Menu `yaml:"Menus"` + // Games is the list of games. + Games map[string]Game `yaml:"Games"` +} + +// LoadFile loads the config from a given file +func LoadFile(path string) (config Config, err error) { + var f *os.File + f, err = os.Open(path) + if err != nil { + return + } + defer f.Close() + decoder := yaml.NewDecoder(f) + if err = decoder.Decode(&config); err != nil { + return + } + return +} -- cgit v1.2.3