Add method to validate configuration

This commit is contained in:
Ryan Cavicchioni 2021-01-20 23:09:37 -06:00
parent e024b45e0a
commit f0b8828af9
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package lumecmd package lumecmd
import ( import (
"errors"
"flag" "flag"
"fmt" "fmt"
"strconv" "strconv"
@ -92,3 +93,12 @@ func GetCommand(name string) (Command, bool) {
cmd, ok := commandRegistry[name] cmd, ok := commandRegistry[name]
return cmd, ok return cmd, ok
} }
// Validate configuration struct
func (c *Config) Validate() error {
var err error
if c.AccessToken == "" {
err = errors.New("access_token is not set")
}
return err
}

View File

@ -33,9 +33,8 @@ func Main(args []string) (int, error) {
config.AccessToken = envAccessToken config.AccessToken = envAccessToken
} }
if config.AccessToken == "" { if err = config.Validate(); err != nil {
err = errors.New("fatal: access token is not set") return ExitError, fmt.Errorf("fatal: %s", err)
return ExitError, err
} }
flag.Parse() flag.Parse()