Using a specific HTTP proxy

To explicitly set the proxy URL, ignoring environment variables, set the ProxyURL variable in a custom http.Transport object that is used by http.Client. The following example creates custom http.Transport and specifies proxyUrlString. The example only has a placeholder value for the proxy and must be replaced with a valid proxy. http.Client is then created and configured to use the custom transport with the proxy:

package mainimport (   "io/ioutil"   "log"   "net/http"   "net/url"   "time")func main() {   proxyUrlString := "http://<proxyIp>:<proxyPort>"   proxyUrl, err := url.Parse(proxyUrlString)   if err != nil {      log.Fatal("Error parsing URL. ", err)   }   // Set up a custom HTTP transport for client customTransport := &http.Transport{ ...

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.