-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_bloomoptions_optiongen.go
82 lines (69 loc) · 2.4 KB
/
gen_bloomoptions_optiongen.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
// Code generated by optiongen. DO NOT EDIT.
// optiongen: github.com/timestee/optiongen
package redisson
// BloomOptions should use newBloomOptions to initialize it
type BloomOptions struct {
// annotation@KeyPrefix(If enabled, Exists and ExistsMulti methods will be available as read-only operations. NOTE: If enabled, minimum redis version should be 7.0.0.)
EnableReadOperation bool
}
// newBloomOptions new BloomOptions
func newBloomOptions(opts ...BloomOption) *BloomOptions {
cc := newDefaultBloomOptions()
for _, opt := range opts {
opt(cc)
}
if watchDogBloomOptions != nil {
watchDogBloomOptions(cc)
}
return cc
}
// ApplyOption apply multiple new option and return the old ones
// sample:
// old := cc.ApplyOption(WithTimeout(time.Second))
// defer cc.ApplyOption(old...)
func (cc *BloomOptions) ApplyOption(opts ...BloomOption) []BloomOption {
var previous []BloomOption
for _, opt := range opts {
previous = append(previous, opt(cc))
}
return previous
}
// BloomOption option func
type BloomOption func(cc *BloomOptions) BloomOption
// WithBloomOptionEnableReadOperation option func for filed EnableReadOperation
func WithBloomOptionEnableReadOperation(v bool) BloomOption {
return func(cc *BloomOptions) BloomOption {
previous := cc.EnableReadOperation
cc.EnableReadOperation = v
return WithBloomOptionEnableReadOperation(previous)
}
}
// InstallBloomOptionsWatchDog the installed func will called when newBloomOptions called
func InstallBloomOptionsWatchDog(dog func(cc *BloomOptions)) { watchDogBloomOptions = dog }
// watchDogBloomOptions global watch dog
var watchDogBloomOptions func(cc *BloomOptions)
// setBloomOptionsDefaultValue default BloomOptions value
func setBloomOptionsDefaultValue(cc *BloomOptions) {
for _, opt := range [...]BloomOption{
WithBloomOptionEnableReadOperation(false),
} {
opt(cc)
}
}
// newDefaultBloomOptions new default BloomOptions
func newDefaultBloomOptions() *BloomOptions {
cc := &BloomOptions{}
setBloomOptionsDefaultValue(cc)
return cc
}
// all getter func
func (cc *BloomOptions) GetEnableReadOperation() bool { return cc.EnableReadOperation }
// BloomOptionsVisitor visitor interface for BloomOptions
type BloomOptionsVisitor interface {
GetEnableReadOperation() bool
}
// BloomOptionsInterface visitor + ApplyOption interface for BloomOptions
type BloomOptionsInterface interface {
BloomOptionsVisitor
ApplyOption(...BloomOption) []BloomOption
}