Use a proxy with Go
HTTP proxy access is completed using net/http, environment variables, Transport, and request timeouts.
Maintained by the ZZHTTP engineering teamUpdated September 20, 2026
The Go standard library can be used by http.Transport.Proxy Use HTTP proxy. The account is closed. us.zzhttp.com:7878 The code reads credentials from the environment.
Go
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
)
func main() {
username, password := os.Getenv("PROXY_USERNAME"), os.Getenv("PROXY_PASSWORD")
if username == "" || password == "" { panic("Missing proxy credentials") }
proxyURL, err := url.Parse("http://us.zzhttp.com:7878")
if err != nil { panic(err) }
proxyURL.User = url.UserPassword(username, password)
transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}
client := &http.Client{Transport: transport, Timeout: 30 * time.Second}
response, err := client.Get("https://ipinfo.io/json")
if err != nil { panic(err) }
defer response.Body.Close()
fmt.Println(response.StatusCode)
if _, err := io.Copy(os.Stdout, response.Body); err != nil { panic(err) }
}
Configuration
- Use
url.ParseI'm going to take you to the next level.PROXY_USERNAMEandPROXY_PASSWORDInject credentials. - Do not log the output of the parsed URL.
Connection
- Set the client to timeout overall.
- Close Body after the response is complete.
Reuse
- Reuse Transport under the same agent.
- Turn off idle connections when configuration changes.
Error handling
- Distinguish between configuration analysis, network errors, and target status.
- Production code adds layering indicators for DNS, dial-up, and TLS.
Did this answer your question?
Feedback is used only to improve the public documentation and does not submit accounts or request information.