LoadConfig 加载配置文件 返回使用的配置文件
(filepath string)
| 104 | |
| 105 | // LoadConfig 加载配置文件 返回使用的配置文件 |
| 106 | func LoadConfig(filepath string) string { |
| 107 | |
| 108 | if filepath == "" { |
| 109 | logs.Debug("use default config") |
| 110 | return loadDefaultConfig() |
| 111 | } |
| 112 | |
| 113 | if _, err := os.Stat(filepath); err != nil { |
| 114 | logs.Debugf("%s not exist, create default config file", filepath) |
| 115 | CreateConfigFile(filepath) |
| 116 | } |
| 117 | |
| 118 | f, err := os.Open(filepath) |
| 119 | if err != nil { |
| 120 | logs.Warnf("read file %s error: %v", filepath, err) |
| 121 | } |
| 122 | |
| 123 | err = json5.NewDecoder(f).Decode(_config) |
| 124 | if err != nil { |
| 125 | logs.Warnf("unmarshal file %s error: %v", filepath, err) |
| 126 | } |
| 127 | |
| 128 | return filepath |
| 129 | } |
| 130 | |
| 131 | var defalutConfigJson []byte |
| 132 |
no test coverage detected