Created
December 16, 2016 19:28
-
-
Save inhies/cd88b4147e18c1f5376a2beea3ffd2fc to your computer and use it in GitHub Desktop.
This code changes http.DefaultClient to use a SOCKS5 proxy
This file contains hidden or 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
// create a socks5 dialer | |
dialer, err := proxy.SOCKS5("tcp", PROXY_ADDR, nil, proxy.Direct) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err) | |
os.Exit(1) | |
} | |
// setup a http client | |
httpTransport := &http.Transport{} | |
// set our socks5 as the dialer | |
httpTransport.Dial = dialer.Dial | |
http.DefaultClient = &http.Client{Transport: httpTransport} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment