Residential proxies with Go (net/http)
Go's standard library handles authenticated proxies directly: set Proxy on an http.Transport to http.ProxyURL(u), with the credentials in u.User. No third-party packages are needed, including for SOCKS5.
Your username and password are on the Proxy generator page after you sign in. Host gw.nodelighthouse.com: port 9000 rotating, 10000 sticky, 11000 SOCKS5.
Get your credentials
Your username and password are on the Proxy generator page of the dashboard. Use the password exactly as shown there; country, state, city and session options all go in the username.
Build the proxy URL with url.UserPassword rather than a string, so special characters in the password are encoded for you.
Send a request through a rotating IP
This client uses port 9000. DisableKeepAlives makes each request open a new connection, and so a new tunnel and a new IP. Without it, Go reuses connections and several requests can share one IP.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
proxyURL := &url.URL{
Scheme: "http",
User: url.UserPassword("<USERNAME>-type-residential-country-us", "<PASSWORD>"),
Host: "gw.nodelighthouse.com:9000",
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
DisableKeepAlives: true,
},
Timeout: 30 * time.Second,
}
for i := 0; i < 3; i++ {
resp, err := client.Get("https://api.ipify.org")
if err != nil {
fmt.Println("error:", err)
continue
}
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
fmt.Println(string(body))
}
}Keep one IP with a sticky session
Use port 10000 and a session id of 8 characters from a-z and 0-9. Here keep-alives can stay on, since every request should use the same IP anyway.
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func stickyClient() *http.Client {
b := make([]byte, 4)
rand.Read(b)
sessionID := hex.EncodeToString(b) // 8 chars, a-f0-9
proxyURL := &url.URL{
Scheme: "http",
User: url.UserPassword("<USERNAME>-type-residential-country-us-lifetime-10-session-"+sessionID, "<PASSWORD>"),
Host: "gw.nodelighthouse.com:10000",
}
return &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
Timeout: 30 * time.Second,
}
}
func main() {
client := stickyClient()
for i := 0; i < 2; i++ {
resp, err := client.Get("https://api.ipify.org")
if err != nil {
fmt.Println("error:", err)
return
}
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
fmt.Println(string(body)) // same IP both times
}
}Use SOCKS5
net/http supports SOCKS5 proxies through the same Proxy field: change the scheme to socks5 and the port to 11000. Go's SOCKS5 client sends the hostname to the proxy, so DNS resolves on the proxy side.
proxyURL := &url.URL{
Scheme: "socks5",
User: url.UserPassword("<USERNAME>-type-residential-country-us", "<PASSWORD>"),
Host: "gw.nodelighthouse.com:11000",
}
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}Questions
- Why does url.Parse fail on my proxy string?
- url.Parse rejects some characters in the user-info part, and the <USERNAME> placeholder contains < and >. Replace the placeholders with your real credentials, or build the URL with url.UserPassword as shown, which encodes them for you.
- Can I set the proxy with an environment variable?
- Yes. http.ProxyFromEnvironment (the default Transport's setting) reads HTTPS_PROXY and HTTP_PROXY, for example HTTPS_PROXY=http://<USERNAME>-type-residential-country-us:<PASSWORD>@gw.nodelighthouse.com:9000. Setting Proxy explicitly is clearer when one program uses several sessions.
- How do I run many sticky sessions at once?
- Create one http.Client per session, each with its own session id in the username. Clients are safe for concurrent use, so goroutines working on the same session can share one.
Related guides: Python requests · Scrapy · Node.js axios
Try it on your own targets
A flat $1.65/GB on every plan, with state and city targeting included. Start with the $2 for 500 MB test pack, paid in crypto.