Ver código fonte

Validate config

tags/v2.0.0-rc1
9seconds 5 anos atrás
pai
commit
59f328b804
1 arquivos alterados com 12 adições e 0 exclusões
  1. 12
    0
      config.go

+ 12
- 0
config.go Ver arquivo

15
 	Secret mtglib.Secret `json:"secret"`
15
 	Secret mtglib.Secret `json:"secret"`
16
 }
16
 }
17
 
17
 
18
+func (c *config) Validate() error {
19
+	if len(c.Secret.Key) == 0 || c.Secret.Host == "" {
20
+		return fmt.Errorf("incorrect secret %s", c.Secret.String())
21
+	}
22
+
23
+	return nil
24
+}
25
+
18
 type configRaw struct {
26
 type configRaw struct {
19
 	Debug     bool   `toml:"debug" json:"debug"`
27
 	Debug     bool   `toml:"debug" json:"debug"`
20
 	Secret    string `toml:"secret" json:"secret"`
28
 	Secret    string `toml:"secret" json:"secret"`
79
 		return nil, fmt.Errorf("cannot parse final config: %w", err)
87
 		return nil, fmt.Errorf("cannot parse final config: %w", err)
80
 	}
88
 	}
81
 
89
 
90
+	if err := conf.Validate(); err != nil {
91
+		return nil, fmt.Errorf("cannot validate config: %w", err)
92
+	}
93
+
82
 	return conf, nil
94
 	return conf, nil
83
 }
95
 }

Carregando…
Cancelar
Salvar