Validate config

This commit is contained in:
9seconds
2021-03-10 12:29:13 +03:00
parent 783c49db37
commit 59f328b804
+12
View File
@@ -15,6 +15,14 @@ type config struct {
Secret mtglib.Secret `json:"secret"`
}
func (c *config) Validate() error {
if len(c.Secret.Key) == 0 || c.Secret.Host == "" {
return fmt.Errorf("incorrect secret %s", c.Secret.String())
}
return nil
}
type configRaw struct {
Debug bool `toml:"debug" json:"debug"`
Secret string `toml:"secret" json:"secret"`
@@ -79,5 +87,9 @@ func parseConfig(reader io.Reader) (*config, error) {
return nil, fmt.Errorf("cannot parse final config: %w", err)
}
if err := conf.Validate(); err != nil {
return nil, fmt.Errorf("cannot validate config: %w", err)
}
return conf, nil
}