-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_option.go
51 lines (41 loc) · 860 Bytes
/
http_option.go
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
package apic
import (
"net/http"
"golang.org/x/time/rate"
)
type HTTPOption func(*HTTPClient)
func WithClient(c *http.Client) HTTPOption {
return func(client *HTTPClient) {
client.client = c
}
}
func WithEncoder(fn func(obj any) ([]byte, error)) HTTPOption {
return func(c *HTTPClient) {
c.encoder = fn
}
}
func WithDecoder(fn func([]byte, any) error) HTTPOption {
return func(c *HTTPClient) {
c.decoder = fn
}
}
func WithBefore(fn func(*http.Request) error) HTTPOption {
return func(c *HTTPClient) {
c.before = fn
}
}
func WithMaxStatus(code int) HTTPOption {
return func(c *HTTPClient) {
c.maxStatus = code
}
}
func WithLogger(lg Logger) HTTPOption {
return func(c *HTTPClient) {
c.logger = lg
}
}
func WithRateLimit(r rate.Limit, b int) HTTPOption {
return func(c *HTTPClient) {
c.limiter = rate.NewLimiter(r, b)
}
}