-
Notifications
You must be signed in to change notification settings - Fork 10
/
conf.go
76 lines (66 loc) · 1.82 KB
/
conf.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
var Conf = &struct {
Email string `yaml:"email"`
Server ServerConf `yaml:"server"`
MMS MMSConf `yaml:"mms"`
Log LogConf `yaml:"log"`
Beanstalk BeanstalkConf `yaml:"beanstalk"`
Database DatabaseConf `yaml:"database"`
Task TaskConf `yaml:"task"`
}{}
type ServerConf struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Cert string `yaml:"cert"`
Key string `yaml:"key"`
User string `yaml:"user"`
Password string `yaml:"password"`
Web string `yaml:"web"`
}
type MMSConf struct {
Enabled int `yaml:"enabled"`
EndpointHost int `yaml:"endpoint_host"`
EndpointPath string `yaml:"endpoint_path"`
Sign string `yaml:"sign"`
TemplateCode string `yaml:"template_code"`
Token string `yaml:"token"`
Tel string `yaml:"tel"`
}
type LogConf struct {
Dir string `yaml:"dir"`
Level string `yaml:"level"`
}
type BeanstalkConf struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
ReserveTube string `yaml:"reserve_tube"`
ReserveTimeout int `yaml:"reserve_timeout"`
}
type DatabaseConf struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
DB string `yaml:"db"`
User string `yaml:"user"`
Password string `yaml:"password"`
Params map[string]string `yaml:"params"`
}
type TaskConf struct {
PollingInterval int `yaml:"polling_interval"`
MaxSend int `yaml:"max_send"`
MaxSendDelay int `yaml:"max_send_delay"`
}
func LoadConf(file string) error {
data, e := ioutil.ReadFile(file)
if e != nil {
return e
}
e = yaml.Unmarshal(data, Conf)
if e != nil {
return e
}
return nil
}