-
Notifications
You must be signed in to change notification settings - Fork 26
/
option.go
48 lines (41 loc) · 938 Bytes
/
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
package resty
import (
"net/http"
)
// WithRetry set retry times if request is failure with 5xx status code. retry is ingore if it is less than 1.
func WithRetry(retry int) Option {
return func(r *Resty) {
if retry > 0 {
r.retry = retry
}
}
}
// WithHeader set header for http request
func WithHeader(header map[string]string) Option {
return func(r *Resty) {
if r.header == nil {
r.header = make(map[string]string)
}
for k, v := range header {
r.header[k] = v
}
}
}
// WithRequestInterceptor intercept request
func WithRequestInterceptor(interceptor func(req *http.Request) error) Option {
return func(r *Resty) {
r.requestInterceptor = interceptor
}
}
// WithTransport set transport
func WithTransport(transport *http.Transport) Option {
return func(r *Resty) {
r.transport = transport
}
}
// WithClient set client
func WithClient(c Client) Option {
return func(r *Resty) {
r.client = c
}
}