forked from cshum/imagor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.go
229 lines (200 loc) · 5.12 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package imagor
import (
"github.com/cshum/imagor/imagorpath"
"go.uber.org/zap"
"time"
)
// Option imagor option
type Option func(app *Imagor)
// WithOptions with nested options
func WithOptions(options ...Option) Option {
return func(app *Imagor) {
for _, option := range options {
if option != nil {
option(app)
}
}
}
}
// WithLogger with logger option
func WithLogger(logger *zap.Logger) Option {
return func(app *Imagor) {
if logger != nil {
app.Logger = logger
}
}
}
// WithLoaders with loaders option
func WithLoaders(loaders ...Loader) Option {
return func(app *Imagor) {
app.Loaders = append(app.Loaders, loaders...)
}
}
// WithStorages with storages option
func WithStorages(savers ...Storage) Option {
return func(app *Imagor) {
app.Storages = append(app.Storages, savers...)
}
}
// WithResultStorages with result storages option
func WithResultStorages(savers ...Storage) Option {
return func(app *Imagor) {
app.ResultStorages = append(app.ResultStorages, savers...)
}
}
// WithProcessors with processor option
func WithProcessors(processors ...Processor) Option {
return func(app *Imagor) {
app.Processors = append(app.Processors, processors...)
}
}
// WithRequestTimeout with request timeout option
func WithRequestTimeout(timeout time.Duration) Option {
return func(app *Imagor) {
if timeout > 0 {
app.RequestTimeout = timeout
}
}
}
// WithCacheHeaderTTL with browser cache header ttl option
func WithCacheHeaderTTL(ttl time.Duration) Option {
return func(app *Imagor) {
if ttl > 0 {
app.CacheHeaderTTL = ttl
}
}
}
// WithCacheHeaderSWR with browser cache header swr option
func WithCacheHeaderSWR(swr time.Duration) Option {
return func(app *Imagor) {
if swr > 0 {
app.CacheHeaderSWR = swr
}
}
}
// WithCacheHeaderNoCache with browser cache header no-cache option
func WithCacheHeaderNoCache(nocache bool) Option {
return func(app *Imagor) {
if nocache {
app.CacheHeaderTTL = 0
}
}
}
// WithLoadTimeout with load timeout option for loader and storage
func WithLoadTimeout(timeout time.Duration) Option {
return func(app *Imagor) {
if timeout > 0 {
app.LoadTimeout = timeout
}
}
}
// WithSaveTimeout with save timeout option for storage
func WithSaveTimeout(timeout time.Duration) Option {
return func(app *Imagor) {
if timeout > 0 {
app.SaveTimeout = timeout
}
}
}
// WithProcessTimeout with process timeout option for processor
func WithProcessTimeout(timeout time.Duration) Option {
return func(app *Imagor) {
if timeout > 0 {
app.ProcessTimeout = timeout
}
}
}
// WithProcessConcurrency maximum number of processor call to be executed simultaneously.
func WithProcessConcurrency(concurrency int64) Option {
return func(app *Imagor) {
if concurrency > 0 {
app.ProcessConcurrency = concurrency
}
}
}
// WithProcessQueueSize maximum number of processor call that can be put to a queue
func WithProcessQueueSize(size int64) Option {
return func(app *Imagor) {
if size > 0 {
app.ProcessQueueSize = size
}
}
}
// WithUnsafe with unsafe option
func WithUnsafe(unsafe bool) Option {
return func(app *Imagor) {
app.Unsafe = unsafe
}
}
// WithAutoWebP with auto WebP option based on browser Accept header
func WithAutoWebP(enable bool) Option {
return func(app *Imagor) {
app.AutoWebP = enable
}
}
// WithAutoAVIF experimental with auto AVIF option based on browser Accept header
func WithAutoAVIF(enable bool) Option {
return func(app *Imagor) {
app.AutoAVIF = enable
}
}
// WithBasePathRedirect with base path redirect option
func WithBasePathRedirect(url string) Option {
return func(app *Imagor) {
app.BasePathRedirect = url
}
}
// WithBaseParams with base params string option
func WithBaseParams(params string) Option {
return func(app *Imagor) {
app.BaseParams = params
}
}
// WithModifiedTimeCheck with option for modified time check of storage against result storage
func WithModifiedTimeCheck(enabled bool) Option {
return func(app *Imagor) {
app.ModifiedTimeCheck = enabled
}
}
// WithDisableErrorBody with disable error body option, resulting empty response on error
func WithDisableErrorBody(disabled bool) Option {
return func(app *Imagor) {
app.DisableErrorBody = disabled
}
}
// WithDisableParamsEndpoint with disable imagor /params endpoint
func WithDisableParamsEndpoint(disabled bool) Option {
return func(app *Imagor) {
app.DisableParamsEndpoint = disabled
}
}
// WithDebug with debug option
func WithDebug(debug bool) Option {
return func(app *Imagor) {
app.Debug = debug
}
}
// WithResultStoragePathStyle with result storage path style hasher option
func WithResultStoragePathStyle(hasher imagorpath.ResultStorageHasher) Option {
return func(app *Imagor) {
if hasher != nil {
app.ResultStoragePathStyle = hasher
}
}
}
// WithStoragePathStyle with storage path style hasher option
func WithStoragePathStyle(hasher imagorpath.StorageHasher) Option {
return func(app *Imagor) {
if hasher != nil {
app.StoragePathStyle = hasher
}
}
}
// WithSigner with URL signature signer option
func WithSigner(signer imagorpath.Signer) Option {
return func(app *Imagor) {
if signer != nil {
app.Signer = signer
}
}
}