Experimental usability stage

This commit is contained in:
Mukhtar Akere
2025-03-22 00:17:07 +01:00
parent d10b679584
commit 738474be16
14 changed files with 212 additions and 148 deletions
+18
View File
@@ -18,6 +18,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
)
@@ -40,6 +41,11 @@ func JoinURL(base string, paths ...string) (string, error) {
return joined, nil
}
var (
once sync.Once
instance *Client
)
type ClientOption func(*Client)
// Client represents an HTTP client with additional capabilities
@@ -83,6 +89,11 @@ func (c *Client) WithLogger(logger zerolog.Logger) *Client {
return c
}
func (c *Client) WithTransport(transport *http.Transport) *Client {
c.client.Transport = transport
return c
}
// WithRetryableStatus adds status codes that should trigger a retry
func (c *Client) WithRetryableStatus(statusCodes ...int) *Client {
for _, code := range statusCodes {
@@ -307,3 +318,10 @@ func Gzip(body []byte) []byte {
}
return b.Bytes()
}
func Default() *Client {
once.Do(func() {
instance = New()
})
return instance
}