mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:44:03 +03:00
Validate config
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user