-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
74 lines (64 loc) · 1.92 KB
/
Copy pathoptions.go
File metadata and controls
74 lines (64 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package flashduty
import (
"fmt"
"net/http"
"net/url"
"time"
)
// Option configures a Client during NewClient.
type Option func(*Client)
// WithBaseURL overrides the API base URL (default https://api.flashcat.cloud).
func WithBaseURL(raw string) Option {
parsed, err := url.Parse(raw)
return func(c *Client) {
if err != nil || parsed == nil || parsed.Host == "" {
c.optionErr = fmt.Errorf("flashduty: invalid base URL %q: %w", raw, err)
return
}
c.BaseURL = parsed
}
}
// WithTimeout sets the HTTP client timeout.
func WithTimeout(d time.Duration) Option {
return func(c *Client) { c.client.Timeout = d }
}
// WithUserAgent sets the User-Agent header sent on every request.
func WithUserAgent(ua string) Option {
return func(c *Client) { c.UserAgent = ua }
}
// WithHTTPClient supplies a custom *http.Client. Nil is ignored.
func WithHTTPClient(hc *http.Client) Option {
return func(c *Client) {
if hc != nil {
c.client = hc
}
}
}
// WithTransport sets a custom http.RoundTripper on the underlying client — the
// idiomatic seam for retry, caching, tracing, or rate-limit middleware (see the
// retry subpackage). Nil is ignored.
func WithTransport(rt http.RoundTripper) Option {
return func(c *Client) {
if rt != nil {
c.client.Transport = rt
}
}
}
// WithLogger sets a custom Logger. Nil is ignored.
func WithLogger(l Logger) Option {
return func(c *Client) {
if l != nil {
c.logger = l
}
}
}
// WithRequestHeaders sets static headers added to every request, applied after
// the SDK's own headers (Content-Type, Accept, User-Agent).
func WithRequestHeaders(h http.Header) Option {
return func(c *Client) { c.requestHeaders = h }
}
// WithRequestHook registers a callback invoked on every outgoing request before
// it is sent — use it to inject per-request headers (e.g. W3C traceparent).
func WithRequestHook(hook func(*http.Request)) Option {
return func(c *Client) { c.requestHook = hook }
}