• 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/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
func main() {
×
15

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

×
30
        cClient := client.New(
×
31
                client.WithTimeout(5*time.Second),
×
32
                client.WithDisableKeepAlives(false),
×
33
                client.WithMaxIdleConns(20),
×
34
                client.WithMaxConnsPerHost(20),
×
35
                client.WithMaxIdleConnsPerHost(20),
×
36
                client.WithContext(context.TODO()),
×
37
                client.WithHeaders(
×
38
                        map[string]string{
×
39
                                "Content-Type":  "application/json",
×
40
                                "Authorization": "Bearer Token"},
×
41
                ),
×
42
                client.WithTLSConfig(&tls.Config{
×
43
                        InsecureSkipVerify: true,
×
44
                        MinVersion:         tls.VersionTLS12,
×
45
                }),
×
46

×
47
                client.WithRetry(
×
48
                        client.RetryConfig{
×
49
                                MaxRetries: 2,
×
50
                                Delay:      1 * time.Second,
×
51
                                UseBackoff: true,
×
52
                                Statuses:   []int{502, 503, 504, 403},
×
53
                                FailoverURLs: []string{
×
54
                                        "http://backup1",
×
NEW
55
                                        "https://httpbin_error.org/post",
×
NEW
56
                                        "http://hosterror"},
×
57
                                EnableLog: true,
×
58
                        }),
×
59
        )
×
60

×
61
        resp, err := cClient.Post("http://api.quick/v1/user",
×
62
                map[string]string{"message": "Hello, POST in Quick!"})
×
63
        if err != nil {
×
64
                log.Fatal(err)
×
65
        }
×
66

67
        // Unmarshal the JSON response (if applicable)
68
        var result map[string]string
×
69
        if err := json.Unmarshal(resp.Body, &result); err != nil {
×
70
                log.Fatal(err)
×
71
        }
×
72
        fmt.Println("POST response:", result)
×
73
}
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