diff options
author | Julien Dessaux | 2021-11-17 10:13:06 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-11-17 10:13:06 +0100 |
commit | c3263c03776401ad1263a9fb8f5a44a8ed44d61b (patch) | |
tree | 7dac91753cb4428ede2ba72fb09eca9ba6c2daab /config/app.go | |
parent | Updated dependencies (diff) | |
download | shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.gz shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.bz2 shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.zip |
Refactored package structure
Diffstat (limited to 'config/app.go')
-rw-r--r-- | config/app.go | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/config/app.go b/config/app.go deleted file mode 100644 index 2eefb98..0000000 --- a/config/app.go +++ /dev/null @@ -1,54 +0,0 @@ -package config - -import ( - "os" - - "github.com/pkg/errors" - "golang.org/x/sys/unix" -) - -// App struct contains the configuration for this application -type App struct { - // WorkingDirectory is the program working directory where the user data, save files and scores are stored - WorkingDirectory string `yaml:"WorkingDirectory"` - // MaxUsers is the maximum amount of registered users to allow - MaxUsers int `yaml:"MaxUsers"` - // AllowRegistration allows registration of new users - AllowRegistration bool `yaml:"AllowRegistration"` - // MaxNickLen Maximum length for a nickname - MaxNickLen int `yaml:"MaxNickLen"` - // MenuMaxIdleTime is the maximum number of seconds a user can be idle on the menu before the program exits - MenuMaxIdleTime int `yaml:"MenuMaxIdleTime"` - // PostLoginCommands is the list of commands to execute upon login, like creating save directories for games - PostLoginCommands []string `yaml:"PostLoginCommands"` -} - -func (a *App) validate() error { - // WorkingDirectory - if err := os.MkdirAll(a.WorkingDirectory, 0700); err != nil { - return errors.Wrapf(err, "Invalid WorkingDirectory : %s", a.WorkingDirectory) - } - if err := unix.Access(a.WorkingDirectory, unix.W_OK|unix.R_OK|unix.X_OK); err != nil { - return errors.Wrapf(err, "invalid WorkingDirectory : %s", a.WorkingDirectory) - } - // MaxUsers - if a.MaxUsers <= 0 { - return errors.New("MaxUsers must be a positive integer") - } - // AllowRegistration is just a bool, nothing to validate - // MaxNickLen - if a.MaxNickLen <= 0 { - return errors.New("MaxNickLen must be a positive integer") - } - // MenuMaxIdleTime - if a.MenuMaxIdleTime <= 0 { - return errors.New("MenuMaxIdleTime must be a positive integer") - } - // PostLoginCommands - for i := 0; i < len(a.PostLoginCommands); i++ { - if err := validateCommand(a.PostLoginCommands[i]); err != nil { - return errors.Wrap(err, "Failed to validate PostLoginCommands") - } - } - return nil -} |