• 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/transport.client/main.go
1
package main
2

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

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

NEW
15
func main() {
×
NEW
16

×
NEW
17
        // Creating a custom HTTP transport with advanced settings.
×
NEW
18
        customTransport := &http.Transport{
×
NEW
19
                Proxy: http.ProxyFromEnvironment, // Uses system proxy settings if available.
×
NEW
20
                TLSClientConfig: &tls.Config{
×
NEW
21
                        InsecureSkipVerify: true,             // Allows insecure TLS connections (not recommended for production).
×
NEW
22
                        MinVersion:         tls.VersionTLS12, // Enforces a minimum TLS version for security.
×
NEW
23
                },
×
NEW
24
                MaxIdleConns:        50,    // Maximum number of idle connections across all hosts.
×
NEW
25
                MaxConnsPerHost:     30,    // Maximum simultaneous connections per host.
×
NEW
26
                MaxIdleConnsPerHost: 10,    // Maximum number of idle connections per host.
×
NEW
27
                DisableKeepAlives:   false, // Enables persistent connections (Keep-Alive).
×
NEW
28
        }
×
NEW
29

×
NEW
30
        // Creating a fully custom *http.Client with the transport and timeout settings.
×
NEW
31
        customHTTPClient := &http.Client{
×
NEW
32
                Timeout: 5 * time.Second, // Sets a global timeout for all requests.
×
NEW
33
        }
×
NEW
34

×
NEW
35
        // Creating a client using both the custom transport and other configurations.
×
NEW
36
        cClient := client.New(
×
NEW
37
                client.WithCustomHTTPClient(customHTTPClient), // Applying the custom HTTP client.
×
NEW
38
                client.WithContext(context.Background()),      // Custom context for request cancellation and deadlines.
×
NEW
39
                client.WithHeaders(map[string]string{
×
NEW
40
                        "Content-Type":  "application/json",
×
NEW
41
                        "Authorization": "Bearer YOUR_ACCESS_TOKEN",
×
NEW
42
                }),
×
NEW
43
                client.WithTransport(customTransport), // Applying the custom transport.
×
NEW
44
                client.WithTimeout(5*time.Second),     // Setting a timeout for requests.
×
NEW
45
                // Retry on specific status codes.
×
NEW
46
                client.WithRetry(
×
NEW
47
                        client.RetryConfig{
×
NEW
48
                                MaxRetries: 2,
×
NEW
49
                                Delay:      1 * time.Second,
×
NEW
50
                                UseBackoff: true,
×
NEW
51
                                Statuses:   []int{500},
×
NEW
52
                                EnableLog:  true,
×
NEW
53
                        }),
×
NEW
54
        )
×
NEW
55

×
NEW
56
        // Define a struct to send as JSON
×
NEW
57
        data := struct {
×
NEW
58
                Message string `json:"message"`
×
NEW
59
        }{
×
NEW
60
                Message: "Hello, POST!",
×
NEW
61
        }
×
NEW
62

×
NEW
63
        resp, err := cClient.Post("http://localhost:3000/v1/user", data)
×
NEW
64
        if err != nil {
×
NEW
65
                log.Fatal(err)
×
NEW
66
        }
×
67

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