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

jeffotoni / quick / 215

04 Mar 2025 04:52PM UTC coverage: 49.633% (+0.4%) from 49.209%
215

push

circleci

jeffotoni
Merge branch 'feature/refactory_http_client'

Carnival went on until dawn, refactoring our client.go, redoing it,
removing all complexity, removing obsolete functions, and leaving
everything clean.
I removed everything unnecessary from the tests and we closed at 91%
coverage.
Now we will focus on the documentation, the pkg go doc, and examples.
We returned the examples to quick for better maintenance and testing.
Now we will evolve.

119 of 160 new or added lines in 5 files covered. (74.38%)

2 existing lines in 1 file now uncovered.

1824 of 3675 relevant lines covered (49.63%)

2715.79 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),
×
NEW
50
                client.WithRetry(
×
51
                        client.RetryConfig{
×
52
                                MaxRetries: 2,
×
53
                                Delay:      1 * time.Second,
×
54
                                UseBackoff: true,
×
55
                                Statuses:   []int{500},
×
56
                                EnableLog:  true,
×
57
                        }),
×
58
        )
×
59

×
60
        // Define a struct to send as JSON
×
61
        data := struct {
×
62
                Message string `json:"message"`
×
63
        }{
×
64
                Message: "Hello, POST!",
×
65
        }
×
66

×
67
        resp, err := cClient.Post("http://localhost:3000/v1/user", data)
×
68
        if err != nil {
×
69
                log.Fatal(err)
×
70
        }
×
71

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