http_client_opt.go 350 B

123456789101112131415161718
  1. package client
  2. import (
  3. "net"
  4. "time"
  5. )
  6. type HttpClientOpt = func(clientCfg *HTTPClient)
  7. func AddDialContext(httpClient *HTTPClient) {
  8. dialContext := (&net.Dialer{
  9. Timeout: 10 * time.Second,
  10. KeepAlive: 10 * time.Second,
  11. }).DialContext
  12. httpClient.Transport.DialContext = dialContext
  13. httpClient.Client.Transport = httpClient.Transport
  14. }