aboutsummaryrefslogtreecommitdiff
path: root/config/app.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-12-24 15:18:24 +0100
committerJulien Dessaux2020-12-24 15:18:24 +0100
commitb4dc5d6841f7ded5995e5f308509b1a3a034cbed (patch)
tree254466925238c53bd51372a57558ec68fdf78205 /config/app.go
parentImplemented the configuration file format (diff)
downloadshell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.gz
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.bz2
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.zip
Began implementing config validation
Diffstat (limited to 'config/app.go')
-rw-r--r--config/app.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/config/app.go b/config/app.go
index 541699c..d7d1051 100644
--- a/config/app.go
+++ b/config/app.go
@@ -1,5 +1,12 @@
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
@@ -15,3 +22,33 @@ type App struct {
// 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); 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
+}