浏览代码

Validate config

tags/v2.0.0-rc1
9seconds 5 年前
父节点
当前提交
59f328b804
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12
    0
      config.go

+ 12
- 0
config.go 查看文件

@@ -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
 }

正在加载...
取消
保存