Using system proxy

Go's default HTTP client will respect the system's HTTP(S) proxy if set through environment variables. Go uses the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables. The lowercase versions are also valid. You can set the environment variable before running the process or set the environment variable in Go with this:

os.Setenv("HTTP_PROXY", "proxyIp:proxyPort")  

After configuring the environment variable(s), any HTTP request made using the default Go HTTP client will respect the proxy settings. Read more about the default proxy settings at https://golang.org/pkg/net/http/#ProxyFromEnvironment.

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.