-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (41 loc) · 1011 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
)
type wssConfig struct {
Key string `json:"keyfile"`
Cert string `json:"certfile"`
}
type config struct {
WSpath string `json:"ws-path"`
Host string `json:"host"`
SecretKey string `json:"secret-key"`
Wss *wssConfig `json:"wss"`
}
var globalConfig config
func loadConfig() error {
f, err := os.Open("config.json")
if err != nil {
return err
}
configText, err := ioutil.ReadAll(f)
if err != nil {
return err
}
err = json.Unmarshal(configText, &globalConfig)
if err != nil {
return err
}
if (globalConfig.WSpath == "") || (globalConfig.Host == "") || (globalConfig.SecretKey == "") {
return errors.New("ws-path, host and secret-key are required (and should not be empty string)")
}
if globalConfig.Wss != nil {
if (globalConfig.Wss.Cert == "") || (globalConfig.Wss.Key == "") {
return errors.New("wss.keyfile and wss.certfile are required when wss is enabled")
}
}
return nil
}