Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active July 7, 2025 15:07
Show Gist options
  • Save Integralist/8a9cb8924f75ae42487fd877b03360e2 to your computer and use it in GitHub Desktop.
Save Integralist/8a9cb8924f75ae42487fd877b03360e2 to your computer and use it in GitHub Desktop.

Revisions

  1. Integralist revised this gist Jul 7, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,14 @@
    > [!TIP]
    > Use `context.WithTimeout` when you need to enforce timeouts on internal operations like database queries or HTTP calls, especially when you want to propagate cancellation signals through the call stack to prevent resource leaks or manage goroutines. It's ideal for fine-grained control within a handler. In contrast, use `http.TimeoutHandler` when you want a simple way to enforce a timeout on the entire HTTP handler response, particularly when you don’t control the handler logic or don’t need to cancel ongoing work—it only cuts off the response after the timeout but doesn’t stop the underlying processing.
    > [!WARNING]
    > Be careful when using `http.TimeoutHander`. If automatically applied to all handlers (as part of a middleware pipeline) then it will not work when it comes to a streaming endpoint (see the relevant Cloudflare article linked in the NOTE below).
    **Client Timeouts**\
    ![Go Client Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > [!NOTE]
    > Read the following articles:\
    > [Resilient HTTP servers using timeouts](https://ieftimov.com/posts/make-resilient-golang-net-http-servers-using-timeouts-deadlines-context-cancellation/)\
    > [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    > Also, [here](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42) are some Transport settings you might want.
  2. Integralist revised this gist Jul 7, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@
    ![Go Client Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > [!NOTE]
    > [Resilient HTTP servers using timeouts](https://ieftimov.com/posts/make-resilient-golang-net-http-servers-using-timeouts-deadlines-context-cancellation/)\
    > [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    > Also, [here](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42) are some Transport settings you might want.
  3. Integralist revised this gist Jul 7, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    **Server Timeouts**\
    ![Go Server Timeouts](https://gist.github.com/user-attachments/assets/38f12dd7-ced3-4707-a25a-6cb28401a915)

    > [!TIP]
    > Use `context.WithTimeout` when you need to enforce timeouts on internal operations like database queries or HTTP calls, especially when you want to propagate cancellation signals through the call stack to prevent resource leaks or manage goroutines. It's ideal for fine-grained control within a handler. In contrast, use `http.TimeoutHandler` when you want a simple way to enforce a timeout on the entire HTTP handler response, particularly when you don’t control the handler logic or don’t need to cancel ongoing work—it only cuts off the response after the timeout but doesn’t stop the underlying processing.
    **Client Timeouts**\
    ![Go Client Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

  4. Integralist revised this gist Jul 7, 2025. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,11 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)
    **Server Timeouts**\
    ![Go Server Timeouts](https://gist.github.com/user-attachments/assets/38f12dd7-ced3-4707-a25a-6cb28401a915)

    > **NOTE:** [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    **Client Timeouts**\
    ![Go Client Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > [!NOTE]
    > [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    > Also, [here](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42) are some Transport settings you might want.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.
  5. Integralist revised this gist Jul 7, 2025. No changes.
  6. Integralist revised this gist May 30, 2025. No changes.
  7. Integralist revised this gist May 28, 2025. No changes.
  8. Integralist revised this gist Apr 17, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > **NOTE:** [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    > Also, [here]([url](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42)) are some Transport settings you might want.
    > Also, [here](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42) are some Transport settings you might want.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

  9. Integralist revised this gist Apr 17, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > **NOTE:** [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    > **NOTE:** [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)\
    > Also, [here]([url](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42)) are some Transport settings you might want.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.
  10. Integralist revised this gist Apr 17, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > NOTE: [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    > **NOTE:** [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    > Also, [here]([url](https://github.com/hashicorp/go-cleanhttp/blob/master/cleanhttp.go#L22-L42)) are some Transport settings you might want.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

  11. Integralist revised this gist May 17, 2022. 2 changed files with 2 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ import (

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Timeout: time.Second * 5,
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ import (

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Timeout: time.Second * 5,
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
  12. Integralist revised this gist May 17, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion basic go http client configuration.go
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ import (

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Timeout: time.Second * 5,
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
  13. Integralist revised this gist Jul 30, 2021. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,11 @@
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

    Additionally, it's important to realise how golang resolves hostnames to IPs (i.e. DNS resolution):
    https://golang.org/pkg/net/#hdr-Name_Resolution
    https://golang.org/pkg/net/#hdr-Name_Resolution

    When cross-compiling binaries you'll find that CGO is typically disabled in favour of the native Go resolver. You can enforce CGO or native like so:

    ```
    env GODEBUG=netdns=cgo+2 go run main.go
    env GODEBUG=netdns=go+2 go run main.go
    ```
  14. Integralist revised this gist Jul 29, 2021. No changes.
  15. Integralist revised this gist Jun 3, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,7 @@

    > NOTE: [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

    Additionally, it's important to realise how golang resolves hostnames to IPs (i.e. DNS resolution):
    https://golang.org/pkg/net/#hdr-Name_Resolution
  16. Integralist revised this gist Jun 3, 2021. 2 changed files with 2 additions and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,4 @@

    > NOTE: [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

    Also, from what I can tell, it seems although you can configure your own `net.Resolver` (with allows you to pass a ctx, with a timeout, to its various lookup methods), the irony appears to be that the `net.Resolver` is only attachable to `http.Transport` (itself you can only attach that to a custom `http.Client`) but by the time the `http.Transport.DialContext` function is called, go has already internally attempted to resolve the hostname given to `http.Client.Do` and so your instance of the `net.Resolver` would only really be applicable to any _additional_ DNS lookups required.
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@ func main() {
    },
    }

    // Also try: https://v4.testmyipv6.com/
    req, err := http.NewRequest("GET", "https://ipv4.lookup.test-ipv6.com/", nil)
    if err != nil {
    log.Fatal(err)
  17. Integralist revised this gist Jun 3, 2021. 1 changed file with 1 addition and 0 deletions.
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,7 @@ func resolveIPv4(addr string) (string, error) {
    m.SetQuestion(dns.Fqdn(url[0]), dns.TypeA)
    m.RecursionDesired = true

    // NOTE: you shouldn't consult or rely on /etc/resolv.conf as it has proven historically to contain nameservers that don't respond.
    config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
    c := new(dns.Client)
    r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port))
  18. Integralist revised this gist Jun 3, 2021. 2 changed files with 39 additions and 3 deletions.
    4 changes: 1 addition & 3 deletions custom dns resolver.go
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // NOTE: this doesn't override the internal go DNS resolver. It happens after the DNS has been resolved and seemingly proxies it onto another DNS resolver?

    package main

    import (
    @@ -38,7 +36,7 @@ func main() {
    httpClient := &http.Client{}

    // Testing the new HTTP client with the custom DNS resolver.
    resp, err := httpClient.Get("https://www.violetnorth.com")
    resp, err := httpClient.Get("https://www.google.com")
    if err != nil {
    log.Fatalln(err)
    }
    38 changes: 38 additions & 0 deletions skip DNS resolution and just pass an IP.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    // This enables you to utilise a package such as https://github.com/miekg/dns to resolve the hostname.

    package main

    import (
    "context"
    "io/ioutil"
    "log"
    "net"
    "net/http"
    "time"
    )
    func main() {
    dialer := &net.Dialer{
    Timeout: 30 * time.Second,
    KeepAlive: 30 * time.Second,
    }

    http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
    if addr == "google.com:443" {
    addr = "216.58.198.206:443"
    }
    return dialer.DialContext(ctx, network, addr)
    }

    resp, err := http.Get("https://www.google.com")
    if err != nil {
    log.Fatalln(err)
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
    log.Fatalln(err)
    }

    log.Println(string(body))
    }
  19. Integralist revised this gist Jun 3, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,3 +2,6 @@

    > NOTE: [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
    Although not explicitly stated, DNS resolution appears to be taken into consideration as part of the overall `http.Client.Timeout` setting. If you need to set your own DNS timeout, then it seems https://github.com/miekg/dns is a popular solution.

    Also, from what I can tell, it seems although you can configure your own `net.Resolver` (with allows you to pass a ctx, with a timeout, to its various lookup methods), the irony appears to be that the `net.Resolver` is only attachable to `http.Transport` (itself you can only attach that to a custom `http.Client`) but by the time the `http.Transport.DialContext` function is called, go has already internally attempted to resolve the hostname given to `http.Client.Do` and so your instance of the `net.Resolver` would only really be applicable to any _additional_ DNS lookups required.
  20. Integralist revised this gist Jun 2, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions custom dns resolver.go
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // NOTE: this doesn't override the internal go DNS resolver. It happens after the DNS has been resolved and seemingly proxies it onto another DNS resolver?

    package main

    import (
  21. Integralist revised this gist Jun 2, 2021. 2 changed files with 51 additions and 0 deletions.
    51 changes: 51 additions & 0 deletions custom dns resolver.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    package main

    import (
    "context"
    "io/ioutil"
    "log"
    "net"
    "net/http"
    "time"
    )

    func main() {
    var (
    dnsResolverIP = "8.8.8.8:53" // Google DNS resolver.
    dnsResolverProto = "udp" // Protocol to use for the DNS resolver
    dnsResolverTimeoutMs = 5000 // Timeout (ms) for the DNS resolver (optional)
    )

    dialer := &net.Dialer{
    Resolver: &net.Resolver{
    PreferGo: true,
    Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
    d := net.Dialer{
    Timeout: time.Duration(dnsResolverTimeoutMs) * time.Millisecond,
    }
    return d.DialContext(ctx, dnsResolverProto, dnsResolverIP)
    },
    },
    }

    dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
    return dialer.DialContext(ctx, network, addr)
    }

    http.DefaultTransport.(*http.Transport).DialContext = dialContext
    httpClient := &http.Client{}

    // Testing the new HTTP client with the custom DNS resolver.
    resp, err := httpClient.Get("https://www.violetnorth.com")
    if err != nil {
    log.Fatalln(err)
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
    log.Fatalln(err)
    }

    log.Println(string(body))
    }
  22. Integralist renamed this gist Jun 2, 2021. 1 changed file with 0 additions and 0 deletions.
  23. Integralist revised this gist Jun 2, 2021. 1 changed file with 49 additions and 0 deletions.
    49 changes: 49 additions & 0 deletions force IPv4 connection type.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    package main

    import (
    "context"
    "crypto/tls"
    "fmt"
    "io"
    "log"
    "net"
    "net/http"
    "time"
    )

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
    InsecureSkipVerify: true,
    },
    DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) {
    return (&net.Dialer{}).DialContext(ctx, "tcp4", addr)
    },
    },
    }

    // Fastly's DNS system controls whether we will report IPv6 addresses for a
    // given hostname, and in the case of developer.fastly.com it CNAMEs to the
    // Fastly map devhub.fastly.net which is configured to opt-in or out of v6
    // support at the map level. The devhub map has dual-stack enabled on it.
    // Therefore, it will announce v6 addresses for it if a client sends AAAA DNS
    // queries for the hostname.
    req, err := http.NewRequest("GET", "https://developer.fastly.com/api/internal/cli-config", nil)
    if err != nil {
    log.Fatal(err)
    }

    res, err := client.Do(req)
    if err != nil {
    log.Fatal(err)
    }

    b, err := io.ReadAll(res.Body)
    if err != nil {
    log.Fatal(err)
    }
    fmt.Printf("%+v\n", string(b))
    }
  24. Integralist revised this gist Jun 2, 2021. 1 changed file with 79 additions and 0 deletions.
    79 changes: 79 additions & 0 deletions force IPv4 connection type (uses third-party dependency).go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    package main

    import (
    "context"
    "crypto/tls"
    "fmt"
    "io"
    "log"
    "net"
    "net/http"
    "strings"
    "time"

    "github.com/miekg/dns"
    )

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
    InsecureSkipVerify: true,
    },
    DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) {
    ipv4, err := resolveIPv4(addr)
    if err != nil {
    return nil, err
    }
    timeout, err := time.ParseDuration("10s")
    if err != nil {
    return nil, err
    }
    return (&net.Dialer{
    Timeout: timeout,
    }).DialContext(ctx, network, ipv4)
    },
    },
    }

    req, err := http.NewRequest("GET", "https://ipv4.lookup.test-ipv6.com/", nil)
    if err != nil {
    log.Fatal(err)
    }

    res, err := client.Do(req)
    if err != nil {
    log.Fatal(err)
    }

    b, err := io.ReadAll(res.Body)
    if err != nil {
    log.Fatal(err)
    }
    fmt.Printf("%+v\n", string(b))
    }

    // resolveIPv4 resolves an address to IPv4 address.
    func resolveIPv4(addr string) (string, error) {
    url := strings.Split(addr, ":")

    m := new(dns.Msg)
    m.SetQuestion(dns.Fqdn(url[0]), dns.TypeA)
    m.RecursionDesired = true

    config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
    c := new(dns.Client)
    r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port))
    if err != nil {
    return "", err
    }
    for _, ans := range r.Answer {
    if a, ok := ans.(*dns.A); ok {
    url[0] = a.A.String()
    }
    }

    return strings.Join(url, ":"), nil
    }
  25. Integralist revised this gist Jun 2, 2021. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion custom go http client.go
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,34 @@ package main

    import (
    "crypto/tls"
    "errors"
    "fmt"
    "io"
    "log"
    "net"
    "net/http"
    "syscall"
    "time"
    )

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Transport: &http.Transport{
    // Avoid: "x509: certificate signed by unknown authority"
    TLSClientConfig: &tls.Config{
    InsecureSkipVerify: true,
    },
    // Inspect the network connection type
    DialContext: (&net.Dialer{
    Control: func(network, address string, c syscall.RawConn) error {
    // Reference: https://golang.org/pkg/net/#Dial
    if network == "tcp4" {
    return errors.New("we don't want you to use IPv4")
    }
    return nil
    },
    }).DialContext,
    },
    }

    @@ -28,5 +43,9 @@ func main() {
    log.Fatal(err)
    }

    fmt.Printf("%+v\n", res)
    b, err := io.ReadAll(res.Body)
    if err != nil {
    log.Fatal(err)
    }
    fmt.Printf("%+v\n", string(b))
    }
  26. Integralist revised this gist Jun 2, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/

    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

    > NOTE: [Guide to `net/http` timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
  27. Integralist revised this gist Jun 2, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,4 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)
    https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/

    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)

  28. Integralist revised this gist Jun 2, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ![Go Network Timeouts](https://user-images.githubusercontent.com/180050/120481192-c6f79080-c3a7-11eb-87de-a93b5de81ec8.png)
  29. Integralist created this gist Jun 2, 2021.
    32 changes: 32 additions & 0 deletions custom go http client.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package main

    import (
    "crypto/tls"
    "fmt"
    "log"
    "net/http"
    "time"
    )

    func main() {
    client := &http.Client{
    Timeout: time.Second * time.Duration(5*time.Second),
    Transport: &http.Transport{
    TLSClientConfig: &tls.Config{
    InsecureSkipVerify: true,
    },
    },
    }

    req, err := http.NewRequest("GET", "https://ipv4.lookup.test-ipv6.com/", nil)
    if err != nil {
    log.Fatal(err)
    }

    res, err := client.Do(req)
    if err != nil {
    log.Fatal(err)
    }

    fmt.Printf("%+v\n", res)
    }