MCPcopy Index your code
hub / github.com/SMNETSTUDIO/Groq2API / InitProxy

Function InitProxy

initialize/proxy.go:12–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func InitProxy() {
13 var proxies []string
14 proxyUrl := os.Getenv("PROXY_URL")
15 if proxyUrl != "" {
16 proxies = append(proxies, proxyUrl)
17 }
18
19 if _, err := os.Stat("proxies.txt"); err == nil {
20 file, _ := os.Open("proxies.txt")
21 defer file.Close()
22 scanner := bufio.NewScanner(file)
23 for scanner.Scan() {
24 proxy := scanner.Text()
25 parsedURL, err := url.Parse(proxy)
26 if err != nil {
27 slog.Warn("proxy url is invalid", "url", proxy, "err", err)
28 continue
29 }
30 // 如果缺少端口信息,不是完整的代理链接
31 if parsedURL.Port() != "" {
32 proxies = append(proxies, proxy)
33 } else {
34 continue
35 }
36 }
37 }
38 if len(proxies) == 0 {
39 proxy := os.Getenv("http_proxy")
40 if proxy != "" {
41 proxies = append(proxies, proxy)
42 }
43 }
44 global.ProxyPool = proxypool.NewIProxyIP(proxies)
45}

Callers 2

mainFunction · 0.92
initFunction · 0.92

Calls 1

NewIProxyIPFunction · 0.92

Tested by

no test coverage detected