Bläddra i källkod

Validate config

tags/v2.0.0-rc1
9seconds 5 år sedan
förälder
incheckning
59f328b804
1 ändrade filer med 12 tillägg och 0 borttagningar
  1. 12
    0
      config.go

+ 12
- 0
config.go Visa fil

@@ -15,6 +15,14 @@ type config struct {
15 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 26
 type configRaw struct {
19 27
 	Debug     bool   `toml:"debug" json:"debug"`
20 28
 	Secret    string `toml:"secret" json:"secret"`
@@ -79,5 +87,9 @@ func parseConfig(reader io.Reader) (*config, error) {
79 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 94
 	return conf, nil
83 95
 }

Laddar…
Avbryt
Spara