-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
executable file
·72 lines (57 loc) · 1.61 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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/heiing/logs"
)
var config *Config = loadDefaultConfig()
type MysqlConfig struct {
Conn string `json:"conn"`
}
type BuilderTemplateConfig struct {
TypeId string `json:"typeId"`
Path string `json:"path"`
}
type CIConfig struct {
CISZ string `json:"cisz"`
CISH string `json:"cish"`
}
type Config struct {
Logs *logs.LogsConfig `json:"logs"`
Mysql *MysqlConfig `json:"mysql"`
CI *CIConfig `json:"ci"`
BuilderTemplateConfigs map[string]*BuilderTemplateConfig
}
func loadDefaultConfig() *Config {
currentPath := logs.GetExecPath()
configFile := filepath.Join(currentPath, "config.json")
buf, err := ioutil.ReadFile(configFile)
if nil != err {
logs.Error("Load config file Faild [", configFile, "]: ", err)
return nil
}
config := &Config{}
if err = json.Unmarshal(buf, config); nil != err {
logs.Error("Parse config file Faild [", configFile, "]: ", err)
return nil
}
logs.SetDefaultLoggerForConfig(config.Logs)
tcp := filepath.Join(currentPath, "config-type-map.json")
tcf, err := os.Open(tcp)
if nil != err {
logs.Error("Open type map config file Faild [", tcp, "]: ", err)
return config
}
tcs := make([]*BuilderTemplateConfig, 0)
if err := json.NewDecoder(tcf).Decode(&tcs); nil != err {
logs.Error("Parse type map config Faild [", tcp, "]: ", err)
return config
}
config.BuilderTemplateConfigs = make(map[string]*BuilderTemplateConfig)
for _, item := range tcs {
config.BuilderTemplateConfigs[item.TypeId] = item
}
return config
}