forked from lestrrat-go/httprc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_gen.go
192 lines (158 loc) · 5.84 KB
/
options_gen.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
// This file is auto-generated by internal/cmd/genoptions/main.go. DO NOT EDIT
package httprc
import (
"time"
"github.com/lestrrat-go/option"
)
type Option = option.Interface
// CacheOption desribes options that can be passed to `New()`
type CacheOption interface {
Option
cacheOption()
}
type cacheOption struct {
Option
}
func (*cacheOption) cacheOption() {}
// FetchOption describes options that can be passed to `(httprc.Fetcher).Fetch()`
type FetchOption interface {
Option
fetchOption()
}
type fetchOption struct {
Option
}
func (*fetchOption) fetchOption() {}
type FetchRegisterOption interface {
Option
fetchOption()
registerOption()
}
type fetchRegisterOption struct {
Option
}
func (*fetchRegisterOption) fetchOption() {}
func (*fetchRegisterOption) registerOption() {}
// RegisterOption desribes options that can be passed to `(httprc.Cache).Register()`
type RegisterOption interface {
Option
registerOption()
}
type registerOption struct {
Option
}
func (*registerOption) registerOption() {}
type identErrSink struct{}
type identFetcherWorkerCount struct{}
type identHTTPClient struct{}
type identMinRefreshInterval struct{}
type identRefreshInterval struct{}
type identRefreshWindow struct{}
type identTransformer struct{}
type identWhitelist struct{}
func (identErrSink) String() string {
return "WithErrSink"
}
func (identFetcherWorkerCount) String() string {
return "WithFetcherWorkerCount"
}
func (identHTTPClient) String() string {
return "WithHTTPClient"
}
func (identMinRefreshInterval) String() string {
return "WithMinRefreshInterval"
}
func (identRefreshInterval) String() string {
return "WithRefreshInterval"
}
func (identRefreshWindow) String() string {
return "WithRefreshWindow"
}
func (identTransformer) String() string {
return "WithTransformer"
}
func (identWhitelist) String() string {
return "WithWhitelist"
}
// WithErrSink specifies the `httprc.ErrSink` object that handles errors
// that occurred during the cache's execution. For example, you will be
// able to intercept errors that occurred during the execution of Transformers.
func WithErrSink(v ErrSink) CacheOption {
return &cacheOption{option.New(identErrSink{}, v)}
}
// WithFetchWorkerCount specifies the number of HTTP fetch workers that are spawned
// in the backend. By default 3 workers are spawned.
func WithFetcherWorkerCount(v int) CacheOption {
return &cacheOption{option.New(identFetcherWorkerCount{}, v)}
}
// WithHTTPClient specififes the HTTP Client object that should be used to fetch
// the resource. For example, if you need an `*http.Client` instance that requires
// special TLS or Authorization setup, you might want to pass it using this option.
func WithHTTPClient(v HTTPClient) FetchRegisterOption {
return &fetchRegisterOption{option.New(identHTTPClient{}, v)}
}
// WithMinRefreshInterval specifies the minimum refresh interval to be used.
//
// When we fetch the key from a remote URL, we first look at the `max-age`
// directive from `Cache-Control` response header. If this value is present,
// we compare the `max-age` value and the value specified by this option
// and take the larger one (e.g. if `max-age` = 5 minutes and `min refresh` = 10
// minutes, then next fetch will happen in 10 minutes)
//
// Next we check for the `Expires` header, and similarly if the header is
// present, we compare it against the value specified by this option,
// and take the larger one.
//
// Finally, if neither of the above headers are present, we use the
// value specified by this option as the interval until the next refresh.
//
// If unspecified, the minimum refresh interval is 1 hour.
//
// This value and the header values are ignored if `WithRefreshInterval` is specified.
func WithMinRefreshInterval(v time.Duration) RegisterOption {
return ®isterOption{option.New(identMinRefreshInterval{}, v)}
}
// WithRefreshInterval specifies the static interval between refreshes
// of resources controlled by `httprc.Cache`.
//
// Providing this option overrides the adaptive token refreshing based
// on Cache-Control/Expires header (and `httprc.WithMinRefreshInterval`),
// and refreshes will *always* happen in this interval.
//
// You generally do not want to make this value too small, as it can easily
// be considered a DoS attack, and there is no backoff mechanism for failed
// attempts.
func WithRefreshInterval(v time.Duration) RegisterOption {
return ®isterOption{option.New(identRefreshInterval{}, v)}
}
// WithRefreshWindow specifies the interval between checks for refreshes.
// `httprc.Cache` does not check for refreshes in exact intervals. Instead,
// it wakes up at every tick that occurs in the interval specified by
// `WithRefreshWindow` option, and refreshes all entries that need to be
// refreshed within this window.
//
// The default value is 15 minutes.
//
// You generally do not want to make this value too small, as it can easily
// be considered a DoS attack, and there is no backoff mechanism for failed
// attempts.
func WithRefreshWindow(v time.Duration) CacheOption {
return &cacheOption{option.New(identRefreshWindow{}, v)}
}
// WithTransformer specifies the `httprc.Transformer` object that should be applied
// to the fetched resource. The `Transform()` method is only called if the HTTP request
// returns a `200 OK` status.
func WithTransformer(v Transformer) RegisterOption {
return ®isterOption{option.New(identTransformer{}, v)}
}
// WithWhitelist specifies the Whitelist object that can control which URLs are
// allowed to be processed.
//
// It can be passed to `httprc.NewCache` as a whitelist applied to all
// URLs that are fetched by the cache, or it can be passed on a per-URL
// basis using `(httprc.Cache).Register()`. If both are specified,
// the url must fulfill _both_ the cache-wide whitelist and the per-URL
// whitelist.
func WithWhitelist(v Whitelist) FetchRegisterOption {
return &fetchRegisterOption{option.New(identWhitelist{}, v)}
}