-
-
Save shuiRong/034516ab39dc0620f86d3d4b405ee3e3 to your computer and use it in GitHub Desktop.
go socks5 client 代理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 配置翻墙用的Client | |
// socks5://127.0.0.1:1085 | |
func createProxyClient(socks5 string) *http.Client { | |
client := &http.Client{} | |
tgProxyURL, err := url.Parse(socks5) | |
if err != nil { | |
fmt.Printf("解析socks5失败: %s", err.Error()) | |
os.Exit(1) | |
} | |
tgDialer, err := proxy.FromURL(tgProxyURL, proxy.Direct) | |
if err != nil { | |
log.Printf("Failed to obtain proxy dialer: %s\n", err) | |
} | |
tgTransport := &http.Transport{ | |
Dial: tgDialer.Dial, | |
} | |
client.Transport = tgTransport | |
return client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment