Created
June 4, 2024 17:45
-
-
Save nikole-dunixi/d4824b6dd810aecf2ca99ae5e8d635a0 to your computer and use it in GitHub Desktop.
Common Golang Http Client Configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779 | |
client := &http.Client{ | |
Timeout: time.Second * 10, | |
Transport: &http.Transport{ | |
Dial: (&net.Dialer{ | |
Timeout: 5 * time.Second, | |
}).Dial, | |
TLSHandshakeTimeout: 5 * time.Second, | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/53369584/1478636 | |
import ( | |
"golang.org/x/net/http2" | |
) | |
client := &http.Client{ | |
Timeout: time.Second * 10, | |
Transport: &http2.Transport{ | |
AllowHTTP: true, | |
DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) { | |
return net.Dial(netw, addr) | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment