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

jeffotoni / quick / 219

06 Mar 2025 06:32PM UTC coverage: 50.442% (+1.3%) from 49.125%
219

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/example/http'

0 of 47 new or added lines in 2 files covered. (0.0%)

1824 of 3616 relevant lines covered (50.44%)

2760.11 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

15
func main() {
×
16

×
NEW
17
        // This example makes a POST request to a server at http://localhost:3000/v1/user.
×
NEW
18
        // For the code to work completely, a server needs to be running on this URL.
×
NEW
19
        // If the server is not running, you can still see the retry logs in the terminal.
×
NEW
20

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

×
34
        // Creating a fully custom *http.Client with the transport and timeout settings.
×
35
        customHTTPClient := &http.Client{
×
36
                Timeout: 5 * time.Second, // Sets a global timeout for all requests.
×
37
        }
×
38

×
39
        // Creating a client using both the custom transport and other configurations.
×
40
        cClient := client.New(
×
41
                client.WithCustomHTTPClient(customHTTPClient), // Applying the custom HTTP client.
×
42
                client.WithContext(context.Background()),      // Custom context for request cancellation and deadlines.
×
43
                client.WithHeaders(map[string]string{
×
44
                        "Content-Type":  "application/json",
×
45
                        "Authorization": "Bearer YOUR_ACCESS_TOKEN",
×
46
                }),
×
47
                client.WithTransport(customTransport), // Applying the custom transport.
×
48
                client.WithTimeout(5*time.Second),     // Setting a timeout for requests.
×
49
                // Retry on specific status codes.
×
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