-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption.go
57 lines (46 loc) · 992 Bytes
/
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
package opensea
import (
"context"
"time"
)
const (
hostProd = "https://api.opensea.io"
hostTest = "https://testnets-api.opensea.io"
)
var defaultOption = &option{baseURL: hostProd}
type option struct {
baseURL string
apiKey string
retryWhenFreqLimit bool
retryInterval time.Duration
retryCount int
}
type OptionFn func(*option)
func WithTestNets(test bool) OptionFn {
return func(o *option) {
if test {
o.baseURL = hostTest
} else {
o.baseURL = hostProd
}
}
}
func WithAPIKey(apiKey string) OptionFn {
return func(o *option) {
o.apiKey = apiKey
}
}
func WithRetryWhenFreqLimit(interval time.Duration, count int) OptionFn {
return func(o *option) {
o.retryWhenFreqLimit = true
o.retryInterval = interval
o.retryCount = count
}
}
type ctxKey int
const (
countCtxKey ctxKey = iota
)
func WrapperCountContext(ctx context.Context, count int) context.Context {
return context.WithValue(ctx, countCtxKey, count)
}