github.com/0chain/gosdk@v1.17.11/zmagmacore/http/client.go (about) 1 // DEPRECATED: This package is deprecated and will be removed in a future release. 2 package http 3 4 import ( 5 "net" 6 "net/http" 7 "time" 8 9 "github.com/hashicorp/go-retryablehttp" 10 ) 11 12 const ( 13 // clientTimeout represents default http.Client timeout. 14 clientTimeout = 10 * time.Second 15 16 // tlsHandshakeTimeout represents default http.Transport TLS handshake timeout. 17 tlsHandshakeTimeout = 5 * time.Second 18 19 // dialTimeout represents default net.Dialer timeout. 20 dialTimeout = 5 * time.Second 21 ) 22 23 // NewClient creates default http.Client with timeouts. 24 func NewClient() *http.Client { 25 return &http.Client{ 26 Timeout: clientTimeout, 27 Transport: &http.Transport{ 28 TLSHandshakeTimeout: tlsHandshakeTimeout, 29 DialContext: (&net.Dialer{ 30 Timeout: dialTimeout, 31 }).DialContext, 32 }, 33 } 34 } 35 36 // NewRetryableClient creates default retryablehttp.Client with timeouts and embedded NewClient result. 37 func NewRetryableClient(retryMax int) *retryablehttp.Client { 38 client := retryablehttp.NewClient() 39 client.HTTPClient = NewClient() 40 client.RetryWaitMax = clientTimeout 41 client.RetryMax = retryMax 42 client.Logger = nil 43 44 return client 45 }