| 1 |
package proton |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
|
| 6 |
"github.com/ProtonMail/gluon/async" |
| 7 |
"github.com/go-resty/resty/v2" |
| 8 |
) |
| 9 |
|
| 10 |
// Option represents a type that can be used to configure the manager. |
| 11 |
type Option interface { |
| 12 |
config(*managerBuilder) |
| 13 |
} |
| 14 |
|
| 15 |
func WithHostURL(hostURL string) Option { |
| 16 |
return &withHostURL{ |
| 17 |
hostURL: hostURL, |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
type withHostURL struct { |
| 22 |
hostURL string |
| 23 |
} |
| 24 |
|
| 25 |
func (opt withHostURL) config(builder *managerBuilder) { |
| 26 |
builder.hostURL = opt.hostURL |
| 27 |
} |
| 28 |
|
| 29 |
func WithAppVersion(appVersion string) Option { |
| 30 |
return &withAppVersion{ |
| 31 |
appVersion: appVersion, |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
type withUserAgent struct { |
| 36 |
userAgent string |
| 37 |
} |
| 38 |
|
| 39 |
func (opt withUserAgent) config(builder *managerBuilder) { |
| 40 |
builder.userAgent = opt.userAgent |
| 41 |
} |
| 42 |
|
| 43 |
func WithUserAgent(userAgent string) Option { |
| 44 |
return &withUserAgent{ |
| 45 |
userAgent: userAgent, |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
type withAppVersion struct { |
| 50 |
appVersion string |
| 51 |
} |
| 52 |
|
| 53 |
func (opt withAppVersion) config(builder *managerBuilder) { |
| 54 |
builder.appVersion = opt.appVersion |
| 55 |
} |
| 56 |
|
| 57 |
func WithTransport(transport http.RoundTripper) Option { |
| 58 |
return &withTransport{ |
| 59 |
transport: transport, |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
type withTransport struct { |
| 64 |
transport http.RoundTripper |
| 65 |
} |
| 66 |
|
| 67 |
func (opt withTransport) config(builder *managerBuilder) { |
| 68 |
builder.transport = opt.transport |
| 69 |
} |
| 70 |
|
| 71 |
type withSkipVerifyProofs struct { |
| 72 |
skipVerifyProofs bool |
| 73 |
} |
| 74 |
|
| 75 |
func (opt withSkipVerifyProofs) config(builder *managerBuilder) { |
| 76 |
builder.verifyProofs = !opt.skipVerifyProofs |
| 77 |
} |
| 78 |
|
| 79 |
func WithSkipVerifyProofs() Option { |
| 80 |
return &withSkipVerifyProofs{ |
| 81 |
skipVerifyProofs: true, |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
func WithRetryCount(retryCount int) Option { |
| 86 |
return &withRetryCount{ |
| 87 |
retryCount: retryCount, |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
type withRetryCount struct { |
| 92 |
retryCount int |
| 93 |
} |
| 94 |
|
| 95 |
func (opt withRetryCount) config(builder *managerBuilder) { |
| 96 |
builder.retryCount = opt.retryCount |
| 97 |
} |
| 98 |
|
| 99 |
func WithCookieJar(jar http.CookieJar) Option { |
| 100 |
return &withCookieJar{ |
| 101 |
jar: jar, |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
type withCookieJar struct { |
| 106 |
jar http.CookieJar |
| 107 |
} |
| 108 |
|
| 109 |
func (opt withCookieJar) config(builder *managerBuilder) { |
| 110 |
builder.cookieJar = opt.jar |
| 111 |
} |
| 112 |
|
| 113 |
func WithLogger(logger resty.Logger) Option { |
| 114 |
return &withLogger{ |
| 115 |
logger: logger, |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
type withLogger struct { |
| 120 |
logger resty.Logger |
| 121 |
} |
| 122 |
|
| 123 |
func (opt withLogger) config(builder *managerBuilder) { |
| 124 |
builder.logger = opt.logger |
| 125 |
} |
| 126 |
|
| 127 |
func WithDebug(debug bool) Option { |
| 128 |
return &withDebug{ |
| 129 |
debug: debug, |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
type withDebug struct { |
| 134 |
debug bool |
| 135 |
} |
| 136 |
|
| 137 |
func (opt withDebug) config(builder *managerBuilder) { |
| 138 |
builder.debug = opt.debug |
| 139 |
} |
| 140 |
|
| 141 |
func WithPanicHandler(panicHandler async.PanicHandler) Option { |
| 142 |
return &withPanicHandler{ |
| 143 |
panicHandler: panicHandler, |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
type withPanicHandler struct { |
| 148 |
panicHandler async.PanicHandler |
| 149 |
} |
| 150 |
|
| 151 |
func (opt withPanicHandler) config(builder *managerBuilder) { |
| 152 |
builder.panicHandler = opt.panicHandler |
| 153 |
} |