MCPcopy Create free account
hub / github.com/aurora-develop/Duck2api / checkProxy

Function checkProxy

initialize/proxy.go:11–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

RegisterRouterFunction · 0.85

Calls 1

NewIProxyIPFunction · 0.92

Tested by

no test coverage detected