Go integration
Send requests through an assigned static endpoint. The example reads credentials from the process environment and uses an HTTP proxy for an HTTPS target by default. It does not fetch or rotate IPs.
Before you start
Set PROXY_HOST, PROXY_PORT, PROXY_USERNAME, and PROXY_PASSWORD in the terminal, container, or deployment platform running the program. Use the current dashboard details and the port for the selected protocol. Keep actual passwords out of source control, logs, and frontend code.
Runtime and dependencies
Use a currently supported Go release; only the standard library is needed. Save as proxy_example.go.
go run proxy_example.goSet up the connection
package main
import (
"context"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func required(name string) string {
value := os.Getenv(name)
if value == "" {
fmt.Fprintln(os.Stderr, "Missing environment variable:", name)
os.Exit(1)
}
return value
}
func main() {
host := strings.Trim(required("PROXY_HOST"), "[]")
port := required("PROXY_PORT")
number, err := strconv.Atoi(port)
if err != nil || number < 1 || number > 65535 {
fmt.Fprintln(os.Stderr, "Invalid PROXY_PORT")
os.Exit(1)
}
scheme := os.Getenv("PROXY_SCHEME")
if scheme == "" { scheme = "http" }
if scheme != "http" && scheme != "socks5h" {
fmt.Fprintln(os.Stderr, "PROXY_SCHEME must be http or socks5h")
os.Exit(1)
}
endpoint := &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(host, port),
User: url.UserPassword(required("PROXY_USERNAME"), required("PROXY_PASSWORD")),
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.Proxy = http.ProxyURL(endpoint)
defer transport.CloseIdleConnections()
client := &http.Client{Transport: transport, Timeout: 30 * time.Second}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://ip123.in/ip.json", nil)
if err != nil { fmt.Fprintln(os.Stderr, "Invalid request"); os.Exit(1) }
response, err := client.Do(request)
if err != nil { fmt.Fprintln(os.Stderr, "Proxy request failed; check network and credentials"); os.Exit(1) }
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
fmt.Fprintln(os.Stderr, "HTTP status:", response.StatusCode)
os.Exit(1)
}
body, err := io.ReadAll(io.LimitReader(response.Body, 1<<20))
if err != nil { fmt.Fprintln(os.Stderr, "Cannot read response"); os.Exit(1) }
fmt.Println(string(body))
}PROXY_SCHEME defaults to http. For SOCKS5, set it to socks5h and use the matching SOCKS5 port so the target hostname is resolved remotely. Switching protocols does not rotate the assigned static exit.
If something goes wrong
If this example succeeds but your workload fails, check the actual request process, SDK proxy configuration, timeouts, and retry policy. Keep TLS certificate verification enabled. The sample prints lookup data or errors without credentials; redact diagnostic logs too. See the FAQ.