Skip to content

Instantly share code, notes, and snippets.

@inhies
Created December 16, 2016 19:28
Show Gist options
  • Save inhies/cd88b4147e18c1f5376a2beea3ffd2fc to your computer and use it in GitHub Desktop.
Save inhies/cd88b4147e18c1f5376a2beea3ffd2fc to your computer and use it in GitHub Desktop.
This code changes http.DefaultClient to use a SOCKS5 proxy
// 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