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

jeffotoni / quick / 233

07 Mar 2025 07:31PM UTC coverage: 56.021% (-0.4%) from 56.44%
233

push

circleci

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

0 of 131 new or added lines in 11 files covered. (0.0%)

4 existing lines in 4 files now uncovered.

2191 of 3911 relevant lines covered (56.02%)

2552.56 hits per line

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

0.0
/example/quick.http.client/full.methods.retry/main.go
1
package main
2

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

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

14
// Example of creating an HTTP client using a fluent and modular approach.
15
// This allows fine-grained control over HTTP settings without requiring a full config struct.
16
//
17
//   - WithTimeout: Sets the HTTP client timeout to 30 seconds.
18
//   - WithDisableKeepAlives: Enables or disables HTTP keep-alives (false = keep-alives enabled).
19
//   - WithMaxIdleConns: Defines the maximum number of idle connections (20).
20
//   - WithMaxConnsPerHost: Sets the maximum connections allowed per host (20).
21
//   - WithMaxIdleConnsPerHost: Sets the maximum number of idle connections per host (20).
22
//   - WithContext: Injects a context for the client (context.TODO() used as placeholder).
23
//   - WithHeaders: Adds custom headers (e.g., Content-Type: application/json).
24
//   - WithTLSConfig: Configures TLS settings, including InsecureSkipVerify and TLS version.
25
//   - WithRetry: Enables automatic retries for specific HTTP status codes (500, 502, 503, 504)
26
//     with exponential backoff (2s-bex) and a maximum of 3 attempts.
27
func main() {
×
28

×
NEW
29
        // Create a new Quick HTTP client with custom settings
×
30
        cClient := client.New(
×
NEW
31
                client.WithTimeout(5*time.Second),   // Sets the request timeout to 5 seconds
×
NEW
32
                client.WithDisableKeepAlives(false), // Enables persistent connections (Keep-Alive)
×
NEW
33
                client.WithMaxIdleConns(20),         // Defines a maximum of 20 idle connections
×
NEW
34
                client.WithMaxConnsPerHost(20),      // Limits simultaneous connections per host to 20
×
NEW
35
                client.WithMaxIdleConnsPerHost(20),  // Limits idle connections per host to 20
×
NEW
36
                client.WithContext(context.TODO()),  // Injects a context (can be used for cancellation)
×
37
                client.WithHeaders(
×
38
                        map[string]string{
×
NEW
39
                                "Content-Type":  "application/json", // Specifies the request content type
×
NEW
40
                                "Authorization": "Bearer Token",     // Adds an authorization token for authentication
×
NEW
41
                        },
×
42
                ),
×
43
                client.WithTLSConfig(&tls.Config{
×
NEW
44
                        InsecureSkipVerify: true,             // ⚠ Disables SSL certificate verification (use with caution)
×
NEW
45
                        MinVersion:         tls.VersionTLS12, // Enforces a minimum TLS version for security
×
46
                }),
×
47
                client.WithRetry(
×
48
                        client.RetryConfig{
×
NEW
49
                                MaxRetries: 2,                         // Allows up to 2 retry attempts for failed requests
×
NEW
50
                                Delay:      1 * time.Second,           // Delay of 1 second between retries
×
NEW
51
                                UseBackoff: true,                      // Enables exponential backoff for retries
×
NEW
52
                                Statuses:   []int{502, 503, 504, 403}, // Retries only on specific HTTP status codes
×
NEW
53
                                FailoverURLs: []string{ // Backup URLs in case the primary request fails
×
54
                                        "http://backup1",
×
55
                                        "https://reqres.in/api/users",
×
NEW
56
                                        "https://httpbin_error.org/post",
×
NEW
57
                                },
×
NEW
58
                                EnableLog: true, // Enables logging for debugging retry behavior
×
59
                        }),
×
60
        )
×
NEW
61
        // Send a POST request to the primary URL
×
NEW
62
        resp, err := cClient.Post("https://httpbin_error.org/post",
×
63
                map[string]string{"message": "Hello, POST in Quick!"})
×
64
        if err != nil {
×
NEW
65
                log.Fatal(err) // Logs an error and exits if the request fails
×
66
        }
×
67

68
        // Unmarshal the JSON response (if applicable)
69
        var result map[string]string
×
70
        if err := json.Unmarshal(resp.Body, &result); err != nil {
×
NEW
71
                log.Fatal(err) // Logs an error if the response cannot be parsed
×
72
        }
×
73

74
        // Print the response
UNCOV
75
        fmt.Println("POST response:", result)
×
76
}
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