package main import ( "fmt" "net/http" "net/url" ) func main() { // create a proxy URL proxyUrl, _ := url.Parse("http://myproxyserver.com:8080") // create a Transport object with the proxy URL transport := &http.Transport{ Proxy: http.ProxyURL(proxyUrl), } // create an http client with the transport object client := &http.Client{ Transport: transport, } // make a GET request through the proxy server resp, err := client.Get("http://example.com") if err != nil { panic(err) } defer resp.Body.Close() // print the response status code fmt.Println(resp.StatusCode) }
package main import ( "fmt" "net/http" ) func main() { // create a Transport object with a custom RoundTripper transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } // create an http client with the transport object client := &http.Client{ Transport: transport, } // make a GET request resp, err := client.Get("http://example.com") if err != nil { panic(err) } defer resp.Body.Close() // print the response status code fmt.Println(resp.StatusCode) }In the above example, we create a `Transport` object with a custom `RoundTripper` that specifies various timeouts and settings like `MaxIdleConns` and `TLSHandshakeTimeout`. We then create an `http.Client` object with the `Transport` object and make a GET request to `http://example.com`. The package library for these examples is net/http.