forked from wangyiwy/oktools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
56 lines (49 loc) · 837 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
51
52
53
54
55
56
package main
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
)
type App struct {
Mode string `yaml:"mode"`
LogFile string `yaml:"log-file"`
}
type Http struct {
Port string `yaml:"port"`
SSL struct {
Crt string `yaml:"crt"`
Key string `yaml:"key"`
} `yaml:"ssl"`
}
type Config struct {
App App `yaml:"app"`
Http Http `yaml:"http"`
}
var config = &Config{}
func init() {
var conf string
if len(os.Args) == 2 {
conf = os.Args[1]
}
if conf == "" {
conf = "conf.yaml"
}
data, err := ioutil.ReadFile(conf)
if err != nil {
log.Println("Config file not found, use default configs.")
config = &Config{
App: App{
Mode: "debug",
LogFile: "oktools.log",
},
Http: Http{
Port: "80",
},
}
}
err = yaml.UnmarshalStrict(data, &config)
if err != nil {
log.Fatalln(err)
}
}