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

jeffotoni / quick / 214

04 Mar 2025 07:11AM UTC coverage: 49.209% (-26.0%) from 75.221%
214

push

circleci

jeffotoni
Merge branch 'feature/refactory_http_client'

new version http client

32 of 1275 new or added lines in 44 files covered. (2.51%)

15 existing lines in 1 file now uncovered.

1803 of 3664 relevant lines covered (49.21%)

2724.12 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

NEW
14
func main() {
×
NEW
15

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

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

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

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

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