初始化配置文件(yaml)
(configFile string)
| 83 | |
| 84 | //初始化配置文件(yaml) |
| 85 | func YamlConfigHandler(configFile string) *AppConfig { |
| 86 | realFile, exists := lookupFile(configFile) |
| 87 | if !exists { |
| 88 | panic("Task:Config:InitConfig 配置文件[" + configFile + "]无法解析 - 无法寻找到指定配置文件") |
| 89 | os.Exit(1) |
| 90 | } |
| 91 | content, err := ioutil.ReadFile(realFile) |
| 92 | if err != nil { |
| 93 | panic("Task:Config:InitYamlConfig 配置文件[" + realFile + "]无法解析 - " + err.Error()) |
| 94 | os.Exit(1) |
| 95 | } |
| 96 | |
| 97 | var config AppConfig |
| 98 | err = yaml.Unmarshal(content, &config) |
| 99 | if err != nil { |
| 100 | panic("Task:Config:InitYamlConfig 配置文件[" + realFile + "]解析失败 - " + err.Error()) |
| 101 | os.Exit(1) |
| 102 | } |
| 103 | return &config |
| 104 | } |
| 105 | |
| 106 | func lookupFile(configFile string) (realFile string, exists bool) { |
| 107 | //add default file lookup |
no test coverage detected