PRIVATEBYTE
ServersProxiesAgentsStatusNetworkAboutFree Proxies
Sign inDeploy

← Docs / Proxies

Datacenter proxies with Go

Go sends traffic through a proxy when you set Transport.Proxy. This page uses the datacenter tier: a US datacenter IP that changes for every new connection.

What you need

Your proxy API key, from the Proxies page in the portal, and the standard library. No packages to install.

export PB_PROXY_KEY="YOUR_KEY"

Send a request through the proxy

package main

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

func main() {
	proxy, _ := url.Parse("http://" + os.Getenv("PB_PROXY_KEY") + ":[email protected]:3128")
	client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}}

	res, err := client.Get("https://api.ipify.org")
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body)) // a US datacenter address
}

Go reads the username and password from the URL and sends them to the proxy for you.

One IP, or a new one each time

Go reuses connections. Every request through this client leaves from one address, as long as the connection stays open. To get a new IP for every request, turn keep-alive off:

client := &http.Client{Transport: &http.Transport{
	Proxy:             http.ProxyURL(proxy),
	DisableKeepAlives: true,
}}

Keep connections open when you want a steady address or a smaller bill. A new HTTPS connection costs about 4 KB of handshake before your first byte. See how usage is counted.

Always read and close the response body. Go only reuses a connection after the body is closed.

Errors

What you see What it means
407 Proxy Authentication Required The API key is wrong or missing.
400 with Unknown tier "datacentre" The tier word is a close misspelling of a real tier. Fix the spelling. A password that is not close to any tier, such as x, uses your account's default tier.
400 Invalid proxy password settings The password asked for something this tier does not do: a country other than US, a session or a TTL.
A site returns 403 The site is refusing datacenter addresses. Try a residential tier such as standard.

A failed tunnel appears as an error from client.Get, for example Proxy Authentication Required.

Related

  • Datacenter proxies with Python requests
  • Datacenter proxies with Node.js
  • How rotating proxies work
  • Datacenter proxies

Try your next connection.

Free proxy credit for eligible new proxy users. No card required. Review the amount and conditions before claiming.

Get free proxy credit →

Explore proxy tiers and paid credit

Related

Proxies: your first requestFind your credentials, copy a cURL or Python example, and check the response.Proxy connection format and tiersWhat goes in the username and password, and what each tier is for.Using SOCKS5Port 1080, the same credentials, and the two things SOCKS5 cannot do.

Still stuck? Open a ticket — tell us what was missing and the article gets fixed.

PRIVATEBYTE

Infrastructure for independent minds.

Service status

Products

Virtual serversProxiesGet free proxy creditAgentsMigration

Resources

Looking glassSecurityBlogNews

Free tools

What is my IPProxy checkerPort checkerDomain checkerDNS lookupPassword generatorVPS price calculator

Company

AboutContactX / TwitterTelegram
© 2026 PrivateByte Ltd
TermsPrivacyAcceptable useRefundsAbuse & legalSLA

Registered in England & Wales · Company no. 15834803 · 128 City Road, London EC1V 2NX