-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
85 lines (70 loc) · 1.27 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
package conf
import (
"io/ioutil"
"github.com/gpmgo/gopm/modules/log"
"os"
"encoding/json"
)
/***
rpc 配置
*/
type ConfigRpc struct {
Addr string // listen at
Pattern string // http handler pattern
// ...
}
/****
reids配置
*/
type ConfigRedis struct {
Host string
DB int
MaxIdle int
MaxActive int
Auth string
}
/****
数据库配置
*/
type ConfigMysql struct {
Host string
Database string
}
/***
交易规则相关配置
*/
type ConfigTrade struct{
TransferFeeSZ float64
TransferFeeSH float64
StampTax float64
Brokerage float64
}
type Config struct {
Rpc ConfigRpc // node rpc
Rds ConfigRedis
Mysql ConfigMysql
Trade ConfigTrade
}
var confData Config
// 加载 配置文件,只加载一次,全局单例
func LoadConfig(filename string, conf interface{}) {
data, err := ioutil.ReadFile(filename)
if err != nil {
log.Error("read config err:", err)
os.Exit(-1)
}
err = json.Unmarshal(data, conf)
if err != nil {
log.Error("Unmarshal config err:", err)
os.Exit(-1)
}
}
// 获取配置对象
func GetConfig() Config {
return confData
}
func init() {
//LoadConfig("H:/mygo/src/github.com/BedeWong/iStock/conf/config.json", &confData)
LoadConfig("./conf/config.json", &confData)
log.Info("config module init ok.")
}