-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
120 lines (100 loc) · 2.79 KB
/
options.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
package evmc
import "time"
const (
defaultConnPool int = 10
defaultReqTimeout time.Duration = 1 * time.Minute
defaultIdleConnTimeout time.Duration = 2 * time.Minute
defaultMaxBatchItems int = 100
defaultMaxBatchSize int = 30 * 1024 * 1024
defaultWsReadBufferSize int = 1024
defaultWsWriteBufferSize int = 1024
defaultWsMessageSizeLimit int = 0 // unlimited
// defaultWsPingInterval time.Duration = 30 * time.Second
// defaultWsPingWriteTimeout time.Duration = 2 * time.Second
// defaultWsPongTimeout time.Duration = 10 * time.Second
)
type options struct {
connPool int
reqTimeout time.Duration
idleConnTimeout time.Duration
maxBatchItems int
maxBatchSize int
wsReadBufferSize int
wsWriteBufferSize int
wsMessageSizeLimit int
// wsPingInterval time.Duration
// wsPingWriteTimeout time.Duration
// wsPongTimeout time.Duration
}
func newOps() *options {
return &options{
connPool: defaultConnPool,
reqTimeout: defaultReqTimeout,
idleConnTimeout: defaultIdleConnTimeout,
maxBatchItems: defaultMaxBatchItems,
maxBatchSize: defaultMaxBatchSize,
wsReadBufferSize: defaultWsReadBufferSize,
wsWriteBufferSize: defaultWsWriteBufferSize,
wsMessageSizeLimit: defaultWsMessageSizeLimit,
// wsPingInterval: defaultWsPingInterval,
// wsPingWriteTimeout: defaultWsPingWriteTimeout,
// wsPongTimeout: defaultWsPongTimeout,
}
}
type optionFunc func(*options)
func (f optionFunc) apply(o *options) {
f(o)
}
type Options interface {
apply(*options)
}
func WithConnPool(pool int) Options {
return optionFunc(func(o *options) {
o.connPool = pool
})
}
func WithReqTimeout(timeout time.Duration) Options {
return optionFunc(func(o *options) {
o.reqTimeout = timeout
})
}
func WithMaxBatchItems(items int) Options {
return optionFunc(func(o *options) {
o.maxBatchItems = items
})
}
func WithMaxBatchSize(size int) Options {
return optionFunc(func(o *options) {
o.maxBatchSize = size
})
}
func WithWsReadBufferSize(size int) Options {
return optionFunc(func(o *options) {
o.wsReadBufferSize = size
})
}
func WithWsWriteBufferSize(size int) Options {
return optionFunc(func(o *options) {
o.wsWriteBufferSize = size
})
}
func WithWsMessageSizeLimit(limit int) Options {
return optionFunc(func(o *options) {
o.wsMessageSizeLimit = limit
})
}
// func WithWsPingInterval(interval time.Duration) Options {
// return optionFunc(func(o *options) {
// o.wsPingInterval = interval
// })
// }
// func WithWsPingWriteTimeout(timeout time.Duration) Options {
// return optionFunc(func(o *options) {
// o.wsPingWriteTimeout = timeout
// })
// }
// func WithWsPongTimeout(timeout time.Duration) Options {
// return optionFunc(func(o *options) {
// o.wsPongTimeout = timeout
// })
// }