-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (40 loc) · 880 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
47
48
49
50
package main
import (
"encoding/json"
"io/ioutil"
"strings"
)
type Config struct {
Port string `json:"port"`
AirqKey string `json:"airq_key"`
FBKey string `json:"fb_key"`
DB struct {
User string `json:"user"`
Password string `json:"password"`
Database string `json:"db"`
} `json:"db"`
Auth struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"auth"`
}
var (
config Config
)
func loadConfig(fileName string) {
file, err := ioutil.ReadFile(fileName)
if err != nil {
panic(err)
}
err = json.Unmarshal(file, &config)
if err != nil {
panic(err)
}
if len(config.Port) < 2 {
panic("port in config.json should be like :8080")
}
if config.DB.User == "" || config.DB.Password == "" || config.DB.Database == "" {
panic("One or more database config are blank")
}
config.Auth.Key = strings.Title(config.Auth.Key)
}