Creating a go socks5 client

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,
}

Recent versions of Go also have SOCKS5 proxy support via the HTTP_PROXY environment variable. You would write your http.Client code as usual, then just set the environment variable at runtime, for example:

HTTP_PROXY="socks5://127.0.0.1:1080/" ./myGoHttpClient

Tags:

Socks

Go