PacketStream integration
Using PacketStream residential proxies with Go
Copy a Go net/http client for PacketStream's HTTPS residential proxy, with timeouts, exit checks, country targeting, and sticky sessions.
Give your Go service one reusable http.Client that routes through PacketStream, enforces a timeout, and keeps the standard transport defaults.
Configure
Read the credentials from the environment and attach the recommended HTTPS proxy to a cloned default transport:
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"time"
)
func main() {
proxyURL := &url.URL{
Scheme: "https",
Host: "proxy.packetstream.io:31111",
User: url.UserPassword(os.Getenv("PACKETSTREAM_USER"), os.Getenv("PACKETSTREAM_AUTH_KEY")),
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.Proxy = http.ProxyURL(proxyURL)
client := &http.Client{Transport: transport, Timeout: 30 * time.Second}
response, err := client.Get("https://ipinfo.io")
if err != nil {
log.Fatal(err)
}
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
response.Body.Close()
log.Fatalf("ipinfo.io returned %s", response.Status)
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
Go’s standard transport also supports authenticated SOCKS5. When SOCKS5 is required, use this proxy URL instead:
proxyURL := &url.URL{
Scheme: "socks5h",
Host: "proxy.packetstream.io:31113",
User: url.UserPassword(os.Getenv("PACKETSTREAM_USER"), os.Getenv("PACKETSTREAM_AUTH_KEY")),
}
Keep the HTTPS configuration above as the recommended default.
Verify your exit
Run the program and inspect the returned ipinfo.io JSON for the observed ip and country.
Country targeting and sticky sessions
Modify the password passed to url.UserPassword:
authKey := os.Getenv("PACKETSTREAM_AUTH_KEY") + "_country-US_session-worker42"
proxyURL.User = url.UserPassword(os.Getenv("PACKETSTREAM_USER"), authKey)
The proxy host, scheme, and port stay the same.
Troubleshooting
- Clone
http.DefaultTransportinstead of replacing it with an empty transport and losing its standard defaults. - Keep
Scheme: "https"paired with port31111; the URL scheme controls how Go connects to the proxy. - Remember that the transport pools connections. Multiple requests on one connection use the same selected exit.
See proxy troubleshooting for proxy-scheme, TLS, authentication, and rotation checks.