MCPcopy Create free account
hub / github.com/devfeel/dottask / YamlConfigHandler

Function YamlConfigHandler

config.go:85–104  ·  view source on GitHub ↗

初始化配置文件(yaml)

(configFile string)

Source from the content-addressed store, hash-verified

83
84//初始化配置文件(yaml)
85func 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
106func lookupFile(configFile string) (realFile string, exists bool) {
107 //add default file lookup

Callers 1

LoadFileConfigMethod · 0.85

Calls 2

lookupFileFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected