Creating a go socks5 client

Rodrigo picture Rodrigo · Nov 7, 2015 · Viewed 9.3k times · Source

So I'm looking at the net/proxy docs and there is no examples at all of how to use any of its methods. I'm looking into using socks5. This is the how the function looks:

func SOCKS5(network, addr string, auth *Auth, forward Dialer) (Dialer, error)

Now everything kinda makes sense except I'm confused about forward which is a type Dialer and the function itself returns a Dialer. Everything else makes sense network, add, auth just forward is throwing me off. How would I set my client up to use the socks5 Dialer?

Answer

Rodrigo picture Rodrigo · Nov 7, 2015

So I was able to find the answer to my question anyone interested how to set up a socks5 client in go here it is:

dialSocksProxy, err := proxy.SOCKS5("tcp", "proxy_ip", nil, proxy.Direct)
if err != nil {
    fmt.Println("Error connecting to proxy:", err)
}
tr := &http.Transport{Dial: dialSocksProxy.Dial}

// Create client
myClient := &http.Client{
    Transport: tr,
}