• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jeffotoni / quick / 220

06 Mar 2025 07:11PM UTC coverage: 50.54% (+0.1%) from 50.442%
220

push

circleci

jeffotoni
fixing and improving some retry failover examples

1 of 47 new or added lines in 5 files covered. (2.13%)

1825 of 3611 relevant lines covered (50.54%)

2764.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/example/quick.http.client/transport.client.failover/main.go
1
package main
2

3
import (
4
        "context"
5
        "crypto/tls"
6
        "fmt"
7
        "log"
8
        "net/http"
9
        "time"
10

11
        "github.com/jeffotoni/quick/http/client"
12
)
13

14
func main() {
×
15

×
16
        // This example makes a POST request to a server at http://localhost:3000/v1/user.
×
17
        // For the code to work completely, a server needs to be running on this URL.
×
18
        // If the server is not running, you can still see the retry logs in the terminal.
×
19
        // Creating a custom HTTP transport with advanced settings.
×
NEW
20
        // FailoverURLs being used
×
21
        customTransport := &http.Transport{
×
22
                Proxy: http.ProxyFromEnvironment, // Uses system proxy settings if available.
×
23
                TLSClientConfig: &tls.Config{
×
24
                        InsecureSkipVerify: true,             // Allows insecure TLS connections (not recommended for production).
×
25
                        MinVersion:         tls.VersionTLS12, // Enforces a minimum TLS version for security.
×
26
                },
×
27
                MaxIdleConns:        50,    // Maximum number of idle connections across all hosts.
×
28
                MaxConnsPerHost:     30,    // Maximum simultaneous connections per host.
×
29
                MaxIdleConnsPerHost: 10,    // Maximum number of idle connections per host.
×
30
                DisableKeepAlives:   false, // Enables persistent connections (Keep-Alive).
×
31
        }
×
32

×
33
        // Creating a fully custom *http.Client with the transport and timeout settings.
×
34
        customHTTPClient := &http.Client{
×
35
                Timeout: 5 * time.Second, // Sets a global timeout for all requests.
×
36
        }
×
37

×
38
        // Creating a client using both the custom transport and other configurations.
×
39
        cClient := client.New(
×
40
                client.WithCustomHTTPClient(customHTTPClient), // Applying the custom HTTP client.
×
41
                client.WithContext(context.Background()),      // Custom context for request cancellation and deadlines.
×
42
                client.WithHeaders(map[string]string{
×
43
                        "Content-Type":  "application/json",
×
44
                        "Authorization": "Bearer YOUR_ACCESS_TOKEN",
×
45
                }),
×
46
                client.WithTransport(customTransport), // Applying the custom transport.
×
47
                client.WithTimeout(5*time.Second),     // Setting a timeout for requests.
×
48
                // Retry on specific status codes.
×
49
                client.WithRetry(
×
50
                        client.RetryConfig{
×
NEW
51
                                MaxRetries:   2,
×
NEW
52
                                Delay:        1 * time.Second,
×
NEW
53
                                UseBackoff:   true,
×
NEW
54
                                Statuses:     []int{500},
×
NEW
55
                                FailoverURLs: []string{"http://hosterror", "https://httpbin.org/post"},
×
NEW
56
                                EnableLog:    true,
×
57
                        }),
×
58
        )
×
59

×
NEW
60
        // call client to POST
×
NEW
61
        resp, err := cClient.Post("http://localhost:3000/v1/user", map[string]string{"message": "Hello Post!!"})
×
62
        if err != nil {
×
63
                log.Fatal(err)
×
64
        }
×
65

66
        // show resp
NEW
67
        fmt.Println("POST response:\n", string(resp.Body))
×
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc