-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
87 lines (72 loc) · 1.28 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
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
77
78
79
80
81
82
83
84
85
86
87
package wopay
import (
"flag"
"io/ioutil"
"log"
toml "github.com/pelletier/go-toml"
)
var tomlConfig = flag.String("config", "../config.toml", "toml config")
type Wechat struct {
AppId string
MchId string
AppSecret string
RedirectUri string
}
type Config struct {
Wechat Wechat
}
var config *Config
func init() {
ConfigInstance()
}
func loadConfig() *toml.Tree {
tree, err := toml.LoadFile(*tomlConfig)
if err != nil {
return nil
}
return tree
}
func ConfigInstance() *Config {
if config == nil {
cfg := &Config{}
//tree := loadConfig()
data, _ := ioutil.ReadFile(*tomlConfig)
log.Println(string(data))
toml.Unmarshal(data, cfg)
config = cfg
}
return config
}
func GetWechat() Wechat {
//wechat := make(Wechat)
//for k, v := range config. {
//wechat[k] = InterfaceToString(v)
//}
return ConfigInstance().Wechat
}
func InterfaceToString(v interface{}) string {
if v, b := v.(string); b {
return v
}
return ""
}
//
//func (w Wechat) Key() string {
// return w["key"]
//}
//
//func (w Wechat) AppId() string {
// return w["appid"]
//}
//
//func (w Wechat) AppSecret() string {
// return w["appsecret"]
//}
//
//func (w Wechat) MchId() string {
// return w["mchid"]
//}
//
//func (w Wechat) RedirectUrl() string {
// return w["redirect_url"]
//}