aboutsummaryrefslogtreecommitdiff
path: root/config/config.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-11-17 10:13:06 +0100
committerJulien Dessaux2021-11-17 10:13:06 +0100
commitc3263c03776401ad1263a9fb8f5a44a8ed44d61b (patch)
tree7dac91753cb4428ede2ba72fb09eca9ba6c2daab /config/config.go
parentUpdated dependencies (diff)
downloadshell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.gz
shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.bz2
shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.zip
Refactored package structure
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go64
1 files changed, 0 insertions, 64 deletions
diff --git a/config/config.go b/config/config.go
deleted file mode 100644
index b68a26a..0000000
--- a/config/config.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package config
-
-import (
- "os"
-
- "github.com/pkg/errors"
- "gopkg.in/yaml.v3"
-)
-
-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 map[string]Menu `yaml:"Menus"`
- // Games is the list of games.
- Games map[string]Game `yaml:"Games"`
-}
-
-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")
- }
- for k, v := range c.Menus {
- if err := v.validate(k); err != nil {
- return err
- }
- }
- // Games
- for k, v := range c.Games {
- if err := v.validate(k); err != nil {
- return err
- }
- }
- return nil
-}
-
-// LoadFile loads the c from a given file
-func LoadFile(path string) (*Config, error) {
- var c *Config
- f, errOpen := os.Open(path)
- if errOpen != nil {
- return nil, errors.Wrapf(errOpen, "Failed to open configuration file %s", path)
- }
- defer f.Close()
- decoder := yaml.NewDecoder(f)
- if err := decoder.Decode(&c); err != nil {
- return nil, errors.Wrap(err, "Failed to decode configuration file")
- }
- if err := c.validate(); err != nil {
- return nil, errors.Wrap(err, "Failed to validate configuration")
- }
- // If all looks good we validate menu consistency
- for _, v := range c.Menus {
- if err := v.validateConsistency(c); err != nil {
- return nil, errors.Wrap(err, "Failed menu consistency checks")
- }
- }
- return c, nil
-}