-
Notifications
You must be signed in to change notification settings - Fork 18
/
builder_option.go
75 lines (62 loc) · 1.91 KB
/
builder_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cute
import (
"net/http"
"time"
)
type options struct {
httpClient *http.Client
httpTimeout time.Duration
httpRoundTripper http.RoundTripper
jsonMarshaler JSONMarshaler
middleware *Middleware
}
// Option ...
type Option func(*options)
// WithHTTPClient is a function for set custom http client
func WithHTTPClient(client *http.Client) Option {
return func(o *options) {
o.httpClient = client
}
}
// WithJSONMarshaler is a function for set custom json marshaler
func WithJSONMarshaler(m JSONMarshaler) Option {
return func(o *options) {
o.jsonMarshaler = m
}
}
// WithCustomHTTPTimeout is a function for set custom http client timeout
func WithCustomHTTPTimeout(t time.Duration) Option {
return func(o *options) {
o.httpTimeout = t
}
}
// WithCustomHTTPRoundTripper is a function for set custom http round tripper
func WithCustomHTTPRoundTripper(r http.RoundTripper) Option {
return func(o *options) {
o.httpRoundTripper = r
}
}
// WithMiddlewareAfter is function for set function which will run AFTER test execution
func WithMiddlewareAfter(after ...AfterExecute) Option {
return func(o *options) {
o.middleware.After = append(o.middleware.After, after...)
}
}
// WithMiddlewareAfterT is function for set function which will run AFTER test execution
func WithMiddlewareAfterT(after ...AfterExecuteT) Option {
return func(o *options) {
o.middleware.AfterT = append(o.middleware.AfterT, after...)
}
}
// WithMiddlewareBefore is function for set function which will run BEFORE test execution
func WithMiddlewareBefore(before ...BeforeExecute) Option {
return func(o *options) {
o.middleware.Before = append(o.middleware.Before, before...)
}
}
// WithMiddlewareBeforeT is function for set function which will run BEFORE test execution
func WithMiddlewareBeforeT(beforeT ...BeforeExecuteT) Option {
return func(o *options) {
o.middleware.BeforeT = append(o.middleware.BeforeT, beforeT...)
}
}