forked from xluohome/smscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
43 lines (37 loc) · 1.15 KB
/
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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Bind string `yaml:"bind"`
Vendors map[string]map[string]string `yaml:"vendors"`
Juheapikey string `yaml:"juheapikey"`
ServiceList map[string]ServiceConfig `yaml:"servicelist"`
Errormsg map[string]string `yaml:"errormsg"`
}
type ServiceConfig struct {
Vendor string `yaml:"vendor"`
Group string `yaml:"group"`
Tpl string `yaml:"smstpl"`
Signname string `yaml:"signname"`
Allowcity []string `yaml:"allowcitys"`
MaxSendNums uint64 `yaml:"maxsendnums"` //每天最大发送数量
Callback string `yaml:"callback"` //成功后回调URL
Mode byte `yaml:"mode"`
Validtime int64 `yaml:"validtime"`
Outformat string `yaml:"outformat"`
}
func (cfg *Config) ParseConfigData(data []byte) error {
if err := yaml.Unmarshal([]byte(data), &cfg); err != nil {
return err
}
return nil
}
func (cfg *Config) ParseConfigFile(fileName string) error {
data, err := ioutil.ReadFile(fileName)
if err != nil {
return err
}
return cfg.ParseConfigData(data)
}