01net/http
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/url"
"time"
)
func main() {
proxy, err := url.Parse("http://USERNAME:PASSWORD@dc.fullstackproxy.com:38417")
if err != nil {
log.Fatal(err)
}
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxy)},
Timeout: 30 * time.Second,
}
res, err := client.Get("https://api.ipify.org")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}The Transport keeps connections alive and reuses them, so requests from one client can share an IP. Set DisableKeepAlives: true on the Transport if every request must rotate, or use a session name when they must not.
02SOCKS5
http.Transport also accepts a socks5:// proxy URL with a login, so the code above works with socks5://USERNAME:PASSWORD@gw.fullstackproxy.com:47631. For raw TCP connections, use golang.org/x/net/proxy:
import "golang.org/x/net/proxy"
auth := &proxy.Auth{User: "USERNAME-country-de", Password: "PASSWORD"}
dialer, err := proxy.SOCKS5("tcp", "gw.fullstackproxy.com:47631", auth, proxy.Direct)
if err != nil {
log.Fatal(err)
}
conn, err := dialer.Dial("tcp", "example.com:443")