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
import (
"errors"
"flag"
"fmt"
"strconv"
@ -92,3 +93,12 @@ func GetCommand(name string) (Command, bool) {
cmd, ok := commandRegistry[name]
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
}
if config.AccessToken == "" {
err = errors.New("fatal: access token is not set")
return ExitError, err
if err = config.Validate(); err != nil {
return ExitError, fmt.Errorf("fatal: %s", err)
}
flag.Parse()