github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/resty/transport.go (about) 1 //go:build go1.13 2 3 // Copyright (c) 2015-2021 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. 4 // resty source code and usage is governed by a MIT style 5 // license that can be found in the LICENSE file. 6 7 package resty 8 9 import ( 10 "net" 11 "net/http" 12 "runtime" 13 "time" 14 ) 15 16 func createTransport(localAddr net.Addr) *http.Transport { 17 dialer := &net.Dialer{ 18 Timeout: 30 * time.Second, 19 KeepAlive: 30 * time.Second, 20 DualStack: true, 21 } 22 if localAddr != nil { 23 dialer.LocalAddr = localAddr 24 } 25 return &http.Transport{ 26 Proxy: http.ProxyFromEnvironment, 27 DialContext: dialer.DialContext, 28 ForceAttemptHTTP2: true, 29 MaxIdleConns: 100, 30 IdleConnTimeout: 90 * time.Second, 31 TLSHandshakeTimeout: 10 * time.Second, 32 ExpectContinueTimeout: 1 * time.Second, 33 MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1, 34 } 35 }