Download initialize/proxy.go from ensionet/groq: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/ensionet/groq/resolve/main/initialize/proxy.go
- Command line
-
hf download hf://spaces/ensionet/groq/initialize/proxy.go
-
curl -L -o proxy.go https://huggingface.co/spaces/ensionet/groq/resolve/main/initialize/proxy.go
977 Bytes
| package initialize | |
| import ( | |
| "bufio" | |
| "groqai2api/global" | |
| "groqai2api/pkg/proxypool" | |
| "log/slog" | |
| "net/url" | |
| "os" | |
| ) | |
| func InitProxy() { | |
| var proxies []string | |
| proxyUrl := os.Getenv("PROXY_URL") | |
| if proxyUrl != "" { | |
| proxies = append(proxies, proxyUrl) | |
| } | |
| if _, err := os.Stat("proxies.txt"); err == nil { | |
| file, _ := os.Open("proxies.txt") | |
| defer file.Close() | |
| scanner := bufio.NewScanner(file) | |
| for scanner.Scan() { | |
| proxy := scanner.Text() | |
| parsedURL, err := url.Parse(proxy) | |
| if err != nil { | |
| slog.Warn("proxy url is invalid", "url", proxy, "err", err) | |
| continue | |
| } | |
| // 如果缺少端口信息,不是完整的代理链接 | |
| if parsedURL.Port() != "" { | |
| proxies = append(proxies, proxy) | |
| } else { | |
| continue | |
| } | |
| } | |
| } | |
| if len(proxies) == 0 { | |
| proxy := os.Getenv("http_proxy") | |
| if proxy != "" { | |
| proxies = append(proxies, proxy) | |
| } | |
| } | |
| global.ProxyPool = proxypool.NewIProxyIP(proxies) | |
| } | |