/
main.go
84 lines (71 loc) · 1.81 KB
/
main.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 configMng
import (
"fmt"
"github.com/wiidz/goutil/helpers"
)
const (
ConfigPath = "./configs/" // 路径写死
DevPath = "dev/"
PdcPath = "pdc/"
AppConfigFileName = "app.json"
WechatConfigFileName = "wechat.json"
MysqlConfigFileName = "mysql.json"
EsConfigFileName = "es.json"
RedisConfigFileName = "redis.json"
OssConfigFileName = "oss.json"
)
var appConfig = AppConfig{}
var osHelper = helpers.OsHelper{}
type ConfigMng struct{}
func init() {
buf := osHelper.GetFileBuf(ConfigPath + AppConfigFileName)
_ = appConfig.UnmarshalJSON(buf)
}
// 获取指定目录里的配置文件
func getTargetDir() string {
var dir string
if appConfig.Debug == false {
dir = PdcPath
} else {
dir = DevPath
}
return ConfigPath + dir
}
func getFileBuf(fileName string) []byte {
return osHelper.GetFileBuf(getTargetDir() + fileName)
}
func (*ConfigMng) GetHttpPort() string {
return appConfig.HttpPort
}
func (*ConfigMng) GetMysql() MysqlConfig {
buf := getFileBuf(MysqlConfigFileName)
mysqlConfig := MysqlConfig{}
_ = mysqlConfig.UnmarshalJSON(buf)
return mysqlConfig
}
func (*ConfigMng) GetRedis() RedisConfig {
buf := getFileBuf(RedisConfigFileName)
redisConfig := RedisConfig{}
_ = redisConfig.UnmarshalJSON(buf)
return redisConfig
}
func (*ConfigMng) GetWechat() WechatConfig {
buf := getFileBuf(WechatConfigFileName)
wechatConfig := WechatConfig{}
_ = wechatConfig.UnmarshalJSON(buf)
return wechatConfig
}
func (*ConfigMng) GetOss() OssConfig {
buf := getFileBuf(OssConfigFileName)
ossConfig := OssConfig{}
_ = ossConfig.UnmarshalJSON(buf)
fmt.Println("ossConfig", ossConfig)
return ossConfig
}
func (*ConfigMng) GetEs() EsConfig {
buf := getFileBuf(EsConfigFileName)
var esConfig EsConfig
_ = esConfig.UnmarshalJSON(buf)
fmt.Println("esConfig", esConfig)
return esConfig
}