Skip to content

Configure TrueProxies with Go

package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
proxyURL, err := url.Parse("http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT")
if err != nil {
panic(err)
}
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
resp, err := client.Get("https://httpbin.org/ip")
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}
proxyURL, _ := url.Parse("http://your_username-country-us:your_password@YOUR_HOST:YOUR_HTTP_PORT")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
proxyURL, _ := url.Parse("http://your_username-session-abc123:your_password@YOUR_HOST:YOUR_HTTP_PORT")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}

Add "time" to the imports, then set a timeout on the client:

client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
Timeout: 30 * time.Second,
}