-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
50 lines (42 loc) · 971 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
package bp
type optionFunc func(*option)
const (
defaultPreloadEnable bool = false
defaultPreloadRate float64 = 0.25
defaultMaxBufSizeFactor float64 = 1.25
defaultAutoGrowEnable bool = false
)
type option struct {
preload bool
preloadRate float64
maxBufSizeFactor float64
autoGrow bool
}
func newOption() *option {
return &option{
preload: defaultPreloadEnable,
preloadRate: defaultPreloadRate,
maxBufSizeFactor: defaultMaxBufSizeFactor,
autoGrow: defaultAutoGrowEnable,
}
}
func Preload(enable bool) optionFunc {
return func(opt *option) {
opt.preload = enable
}
}
func PreloadRate(rate float64) optionFunc {
return func(opt *option) {
opt.preloadRate = rate
}
}
func MaxBufSizeFactor(factor float64) optionFunc {
return func(opt *option) {
opt.maxBufSizeFactor = factor
}
}
func AutoGrow(enable bool) optionFunc {
return func(opt *option) {
opt.autoGrow = enable
}
}