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

jeffotoni / quick / 228

07 Mar 2025 12:19PM UTC coverage: 56.816% (+0.2%) from 56.652%
228

push

circleci

jaquelineabreu
fix: failoverURL

0 of 34 new or added lines in 9 files covered. (0.0%)

2159 of 3800 relevant lines covered (56.82%)

2626.94 hits per line

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

0.0
/example/quick.http.client/http.client.config/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
        // Configuring the HTTP client using a structured approach.
×
17
        //
×
18
        // The following settings are applied to the HTTP client:
×
19
        // - Timeout: Sets the maximum duration for requests (20 seconds).
×
20
        // - DisableKeepAlives: Controls whether keep-alive connections are disabled (false = keep-alives enabled).
×
21
        // - MaxIdleConns: Defines the maximum number of idle connections across all hosts (20).
×
22
        // - MaxConnsPerHost: Sets the maximum number of simultaneous connections to a single host (20).
×
23
        // - MaxIdleConnsPerHost: Defines the maximum number of idle connections per host (20).
×
24
        // - TLSClientConfig: Configures TLS settings, including:
×
25
        //     * InsecureSkipVerify: false (enables strict TLS verification).
×
26
        //     * MinVersion: TLS 1.2 (ensures a minimum TLS version for security).
×
27
        //
×
28
        // Using WithHTTPClientConfig(cfg), all the configurations are applied at once.
×
29
        cfg := &client.HTTPClientConfig{
×
30
                Timeout:             20 * time.Second,
×
31
                DisableKeepAlives:   false,
×
32
                MaxIdleConns:        20,
×
33
                MaxConnsPerHost:     20,
×
34
                MaxIdleConnsPerHost: 20,
×
35
                TLSClientConfig: &tls.Config{
×
36
                        InsecureSkipVerify: false,
×
37
                        MinVersion:         tls.VersionTLS12,
×
38
                },
×
39
        }
×
40

×
41
        // Creating an HTTP client with the pre-defined configuration.
×
42
        //
×
43
        // - WithContext: Sets a custom context for handling request cancellation and deadlines.
×
44
        // - WithHeaders: Adds a map of default headers (e.g., "Content-Type: application/xml").
×
45
        // - WithHTTPClientConfig: Applies the entire configuration object (cfg) to the client.
×
46
        cClient := client.New(
×
47
                client.WithContext(context.TODO()),
×
48
                client.WithHeaders(map[string]string{"Content-Type": "application/xml"}),
×
49
                client.WithHTTPClientConfig(cfg),
×
50
                client.WithRetry(
×
51
                        client.RetryConfig{
×
52
                                MaxRetries: 2,
×
53
                                Delay:      1 * time.Second,
×
54
                                UseBackoff: true,
×
55
                                Statuses:   []int{500},
×
56
                                FailoverURLs: []string{
×
57
                                        "http://backup1",
×
58
                                        "https://httpbin_error.org/post",
×
NEW
59
                                        "https://httpbin.org/post "},
×
60
                                EnableLog: true,
×
61
                        }),
×
62
        )
×
63

×
64
        // Define a struct to send as JSON
×
65
        data := struct {
×
66
                Message string `json:"message"`
×
67
        }{
×
68
                Message: "Hello, POST!",
×
69
        }
×
70

×
71
        resp, err := cClient.Post("http://localhost:3000/v1/user", data)
×
72
        if err != nil {
×
73
                log.Fatal(err)
×
74
        }
×
75

76
        // Unmarshal the JSON response (if applicable)
77
        var result map[string]string
×
78
        if err := json.Unmarshal(resp.Body, &result); err != nil {
×
79
                log.Fatal(err)
×
80
        }
×
81
        fmt.Println("POST response:", result["message"])
×
82
}
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