从本地文件或者http链接读取配置文件内容
(path string)
| 56 | |
| 57 | // 从本地文件或者http链接读取配置文件内容 |
| 58 | func ReadFile(path string) ([]byte, error) { |
| 59 | if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { |
| 60 | resp, err := tool.GetHttpClient().Get(path) |
| 61 | if err != nil { |
| 62 | return nil, errors.New("config file http get fail") |
| 63 | } |
| 64 | defer resp.Body.Close() |
| 65 | return ioutil.ReadAll(resp.Body) |
| 66 | } else { |
| 67 | if _, err := os.Stat(path); os.IsNotExist(err) { |
| 68 | return nil, err |
| 69 | } |
| 70 | return ioutil.ReadFile(path) |
| 71 | } |
| 72 | } |
no test coverage detected