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

jeffotoni / quick / 225

06 Mar 2025 10:06PM UTC coverage: 48.491% (-0.4%) from 48.866%
225

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/example/http'

more examples

0 of 73 new or added lines in 10 files covered. (0.0%)

1832 of 3778 relevant lines covered (48.49%)

2641.88 hits per line

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

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

3
import (
4
        "fmt"
5
        "log"
6
        "time"
7

8
        "github.com/jeffotoni/quick/http/client"
9
)
10

11
func main() {
×
12
        // Create a new HTTP client with specific configurations.
×
13
        cClient := client.New(
×
14
                // Set a timeout for all requests made by this client to 10 seconds.
×
15
                // This helps prevent the client from hanging indefinitely on requests.
×
16
                client.WithTimeout(10*time.Second),
×
17

×
18
                // Set default headers for all requests made by this client.
×
19
                // Here, 'Content-Type' is set to 'application/json' which is typical for API calls.
×
20
                client.WithHeaders(map[string]string{
×
21
                        "Content-Type": "application/json",
×
22
                }),
×
23

×
24
                // Enable automatic retry mechanism with specific configurations.
×
25
                // This is useful for handling intermittent errors and ensuring robustness.
×
26
                client.WithRetry(
×
27
                        client.RetryConfig{
×
28
                                MaxRetries: 2,                    // Retry failed requests up to two times.
×
29
                                Delay:      1 * time.Second,      // Wait for 1 second before retrying.
×
30
                                UseBackoff: true,                 // Use exponential backoff strategy for retries.
×
31
                                Statuses:   []int{500, 502, 503}, // HTTP status codes that trigger a retry.
×
32
                                FailoverURLs: []string{ // Alternate URLs to try if the main request fails.
×
33
                                        "http://hosterror",
×
NEW
34
                                        "https://httpbin_error.org/post",
×
35
                                },
×
36
                                EnableLog: true, // Enable logging for retry operations.
×
37
                        }),
×
38
        )
×
39

×
40
        // Perform a POST request using the configured HTTP client.
×
41
        // Includes a JSON payload with a "name" key.
×
NEW
42
        resp, err := cClient.Post("https://httpbin.org/post", map[string]string{
×
43
                "name": "jeffotoni in action with Quick!!!",
×
44
        })
×
45

×
46
        // Check if there was an error with the POST request.
×
47
        if err != nil {
×
48
                // If an error occurs, log the error and terminate the program.
×
49
                log.Fatalf("POST request failed: %v", err)
×
50
        }
×
51

52
        // Print the response from the server to the console.
53
        fmt.Println("POST Form Response:", string(resp.Body))
×
54
}
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