Before you start
Nefo offers residential proxies across 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).
Go's standard library handles HTTP proxies natively; SOCKS5 uses the golang.org/x/net/proxy package.
- Go 1.21+ installed
- golang.org/x/net/proxy added for SOCKS5 (optional)
- A Nefo account with prepaid bandwidth
- A username/password from /dashboard/generator
- Your target country token
Go HTTP client proxy example
Set the proxy on a transport:
For SOCKS5, build a dialer with proxy.SOCKS5 and assign it to the transport. Change the country token to target any of 227 countries.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"golang.org/x/net/proxy"
)
func main() {
proxyURL, _ := url.Parse("http://USERNAME-country-us:[email protected]:9000")
tr := &http.Transport{Proxy: http.ProxyURL(proxyURL)}
client := &http.Client{Transport: tr}
resp, _ := client.Get("https://api.ipify.org")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
// socks5Client dials the SOCKS5 gateway instead of the HTTP one.
func socks5Client() (*http.Client, error) {
dialer, err := proxy.SOCKS5("tcp", "gw.nefo.net:11000", &proxy.Auth{
User: "USERNAME-country-us",
Password: "PASSWORD",
}, nil)
if err != nil {
return nil, err
}
tr := &http.Transport{Dial: dialer.Dial}
return &http.Client{Transport: tr}, nil
}Go rotating vs sticky proxy sessions
Rotating sessions give a new residential IP per request: HTTP port 9000 or SOCKS5 port 11000. Reuse the same client and each request may exit from a different IP.
Sticky sessions hold one IP from 1 minute up to 24 hours: HTTP port 10000 or SOCKS5 port 12000. Build the client with a token like USERNAME-country-us-session-worker2-lifetime-30 to keep one IP across a batch of calls.
Geo-targeting in the Go proxy username
Targeting is set through username tokens: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username changes, so the transport wiring stays identical.
Use the network lawfully, respect the target site's terms of service, and stay within applicable law and reasonable request rates.
Frequently asked questions
Yes for HTTP proxies. When the username token and password are part of the URL passed to http.ProxyURL, Go sends the Proxy-Authorization header for you, so you do not set it by hand.
Import golang.org/x/net/proxy and build a dialer with proxy.SOCKS5 pointing at port 11000 (rotating) or 12000 (sticky). Pass your username token and password in proxy.Auth, then assign the dialer to the transport.
Use port 10000 and a session token such as USERNAME-country-us-session-abc-lifetime-30 in the client's proxy URL. Reuse the same client for the whole batch so every call exits from one IP, for up to 24 hours.
Rotating port 9000 (HTTP) and 11000 (SOCKS5) assign a new residential IP per request by design. Switch to port 10000 or 12000 with a -session- token if you need a stable address. See rotating vs sticky.
Set the country token in the username, for example USERNAME-country-au. The transport code stays the same because only the username string changes between regions.
No. Generating credentials is free, and only the traffic your client routes through the proxy uses prepaid bandwidth.