Skip to content

Commit

Permalink
chore: improve config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
H777K committed Nov 20, 2023
1 parent d6a9791 commit 74d4693
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type OperatorConfig struct {
}

type AppConfig struct {
Garm GarmConfig `koanf:"garm" validate:"required"`
Operator OperatorConfig `koanf:"operator" validate:"required"`
Garm GarmConfig `koanf:"garm"`
Operator OperatorConfig `koanf:"operator"`
}

var Config AppConfig
Expand Down Expand Up @@ -83,10 +83,7 @@ func ReadConfig(f *pflag.FlagSet, configFile string) error {

validate := validator.New(validator.WithRequiredStructEnabled())
if err := validate.Struct(&Config); err != nil {
if strings.Contains(err.Error(), "required") {
return errors.Wrap(err, "set config with flag, env or in config file")
}
return errors.Wrap(err, "missing required attributes")
return errors.Wrap(err, "invalid config: set with env, flag or in config file")
}

return nil
Expand Down

0 comments on commit 74d4693

Please sign in to comment.