Go

How to Use SocksNode Residential Proxies with Go

Quick answer

To use SocksNode residential proxies in Go, parse the gateway URL with net/url and set it as the Proxy on an http.Transport, then attach that transport to your http.Client. Use global.socksnode.com:9000 for rotating HTTP or 10000 with a session token for sticky IPs, and put geo targeting tokens in the username.

Before you start

SocksNode offers residential proxies across 195+ 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 SocksNode account with prepaid bandwidth
A username/password from /dashboard/generator
Your target country token

Configure the proxy in Go

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 195+ countries.

package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"

	"golang.org/x/net/proxy"
)

func main() {
	proxyURL, _ := url.Parse("http://USERNAME-country-us:PASSWORD@global.socksnode.com: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", "global.socksnode.com: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
}

Rotating vs sticky 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 and compliance

Targeting is set through username tokens: country across 195+ 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.

See also

Frequently asked questions

Does Go handle proxy auth automatically?

Yes for HTTP. When you include the username token and password in the URL passed to http.ProxyURL, Go sends the Proxy-Authorization header for you.

How do I use SOCKS5 in Go?

Use golang.org/x/net/proxy with proxy.SOCKS5 pointing at port 11000 (rotating) or 12000 (sticky), supplying your username token and password in proxy.Auth.

How do I keep one IP across requests?

Use port 10000 and a session token like USERNAME-country-us-session-abc-lifetime-30 in the client's proxy URL to hold the IP for up to 24 hours.

How do I target a country?

Set the country token in the username, such as USERNAME-country-au, choosing from 195+ countries plus US state, city, and ASN targeting.

Is creating credentials billed?

No. Generating credentials is free; only the traffic your client routes through the proxy consumes prepaid bandwidth.

Related posts

All posts

Get started.

Create an account, generate a credential, connect. The API is the same one the dashboard uses.