Please consider this question.
ourClient
is an *http.Client
- once it is generated, how can TLSClientConfig
(which is of type tls.Config{}
) alone be changed of this http.Client?
package main
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"time"
)
func main() {
transport := &http.Transport{
TLSHandshakeTimeout: 10 * time.Second,
Dial: (&net.Dialer{
Timeout: 1 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSClientConfig: &tls.Config{},
}
ourClient := &http.Client{
Timeout: 5 * time.Second,
Transport: transport,
}
fmt.Printf("http.Client Timeout %v\n", ourClient.Timeout)
ourClient.Timeout = 3 * time.Second
fmt.Printf("http.Client Timeout %v\n", ourClient.Timeout)
// how do I replace the TLSClientConfig in ourClient
// newTLSClientConfig := &tls.Config{}
// ourClient.Transport.TLSClientConfig = newTLSClientConfig
// ourClient.Transport.TLSClientConfig undefined (type http.RoundTripper has no field or method TLSClientConfig)
fmt.Printf("http: %#v\n", ourClient)
}
(Also posted as https://go.dev/play/p/v1HJLZ-MhhH)