MCPcopy
hub / github.com/zu1k/proxypool / ReadFile

Function ReadFile

config/config.go:58–72  ·  view source on GitHub ↗

从本地文件或者http链接读取配置文件内容

(path string)

Source from the content-addressed store, hash-verified

56
57// 从本地文件或者http链接读取配置文件内容
58func 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}

Callers 2

initGettersFunction · 0.92
ParseFunction · 0.85

Calls 2

GetHttpClientFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected