forked from ProtonMail/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 4
/
option.go
153 lines (120 loc) · 2.65 KB
/
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package proton
import (
"net/http"
"github.com/ProtonMail/gluon/async"
"github.com/go-resty/resty/v2"
)
// Option represents a type that can be used to configure the manager.
type Option interface {
config(*managerBuilder)
}
func WithHostURL(hostURL string) Option {
return &withHostURL{
hostURL: hostURL,
}
}
type withHostURL struct {
hostURL string
}
func (opt withHostURL) config(builder *managerBuilder) {
builder.hostURL = opt.hostURL
}
func WithAppVersion(appVersion string) Option {
return &withAppVersion{
appVersion: appVersion,
}
}
type withUserAgent struct {
userAgent string
}
func (opt withUserAgent) config(builder *managerBuilder) {
builder.userAgent = opt.userAgent
}
func WithUserAgent(userAgent string) Option {
return &withUserAgent{
userAgent: userAgent,
}
}
type withAppVersion struct {
appVersion string
}
func (opt withAppVersion) config(builder *managerBuilder) {
builder.appVersion = opt.appVersion
}
func WithTransport(transport http.RoundTripper) Option {
return &withTransport{
transport: transport,
}
}
type withTransport struct {
transport http.RoundTripper
}
func (opt withTransport) config(builder *managerBuilder) {
builder.transport = opt.transport
}
type withSkipVerifyProofs struct {
skipVerifyProofs bool
}
func (opt withSkipVerifyProofs) config(builder *managerBuilder) {
builder.verifyProofs = !opt.skipVerifyProofs
}
func WithSkipVerifyProofs() Option {
return &withSkipVerifyProofs{
skipVerifyProofs: true,
}
}
func WithRetryCount(retryCount int) Option {
return &withRetryCount{
retryCount: retryCount,
}
}
type withRetryCount struct {
retryCount int
}
func (opt withRetryCount) config(builder *managerBuilder) {
builder.retryCount = opt.retryCount
}
func WithCookieJar(jar http.CookieJar) Option {
return &withCookieJar{
jar: jar,
}
}
type withCookieJar struct {
jar http.CookieJar
}
func (opt withCookieJar) config(builder *managerBuilder) {
builder.cookieJar = opt.jar
}
func WithLogger(logger resty.Logger) Option {
return &withLogger{
logger: logger,
}
}
type withLogger struct {
logger resty.Logger
}
func (opt withLogger) config(builder *managerBuilder) {
builder.logger = opt.logger
}
func WithDebug(debug bool) Option {
return &withDebug{
debug: debug,
}
}
type withDebug struct {
debug bool
}
func (opt withDebug) config(builder *managerBuilder) {
builder.debug = opt.debug
}
func WithPanicHandler(panicHandler async.PanicHandler) Option {
return &withPanicHandler{
panicHandler: panicHandler,
}
}
type withPanicHandler struct {
panicHandler async.PanicHandler
}
func (opt withPanicHandler) config(builder *managerBuilder) {
builder.panicHandler = opt.panicHandler
}