Skip to content

Commit ac8336b

Browse files
author
Andrew
committedMar 2, 2024
Proxy from environment variable
1 parent 6234b66 commit ac8336b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed
 

‎client/client.go

+24-11
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,32 @@ func NewClient() (tls_client.HttpClient, error) {
1919
// tls_client.WithInsecureSkipVerify(),
2020
}
2121

22-
_, err := os.Stat("proxy.txt")
23-
if err == nil {
24-
proxyConfig, readErr := os.ReadFile("proxy.txt")
25-
if readErr != nil {
26-
fmt.Fprintln(os.Stderr, "Error reading file proxy.txt:", readErr)
27-
return nil, readErr
22+
proxyAddress := os.Getenv("HTTP_PROXY")
23+
if proxyAddress == "" {
24+
proxyAddress = os.Getenv("http_proxy")
25+
} else {
26+
}
27+
28+
if proxyAddress != "" {
29+
if strings.HasPrefix(proxyAddress, "http://") || strings.HasPrefix(proxyAddress, "socks5://") {
30+
proxyOption := tls_client.WithProxyUrl(proxyAddress)
31+
options = append(options, proxyOption)
2832
}
33+
} else {
34+
_, err := os.Stat("proxy.txt")
35+
if err == nil {
36+
proxyConfig, readErr := os.ReadFile("proxy.txt")
37+
if readErr != nil {
38+
fmt.Fprintln(os.Stderr, "Error reading file proxy.txt:", readErr)
39+
return nil, readErr
40+
}
2941

30-
proxyAddress := strings.TrimSpace(string(proxyConfig))
31-
if proxyAddress != "" {
32-
if strings.HasPrefix(proxyAddress, "http://") || strings.HasPrefix(proxyAddress, "socks5://") {
33-
proxyOption := tls_client.WithProxyUrl(proxyAddress)
34-
options = append(options, proxyOption)
42+
proxyAddress := strings.TrimSpace(string(proxyConfig))
43+
if proxyAddress != "" {
44+
if strings.HasPrefix(proxyAddress, "http://") || strings.HasPrefix(proxyAddress, "socks5://") {
45+
proxyOption := tls_client.WithProxyUrl(proxyAddress)
46+
options = append(options, proxyOption)
47+
}
3548
}
3649
}
3750
}

0 commit comments

Comments
 (0)