-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_gen_optiongen.go
139 lines (124 loc) · 2.91 KB
/
gen_gen_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
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
// Code generated by optiongen. DO NOT EDIT.
// optiongen: github.com/timestee/optiongen
package gcache
import (
"bitbucket.org/funplus/gcache/cache"
"time"
)
type Options struct {
Shards int32
Expiration time.Duration
EvictStrategy cache.EVICT_STRATEGY
CleanInterval time.Duration
MaxEntrySize uint32
Hasher Hasher
OnRemoveCallbackFunc cache.EvictCallback
Development bool
Logger Logger
}
func (cc *Options) SetOption(opt Option) {
_ = opt(cc)
}
func (cc *Options) ApplyOption(opts ...Option) {
for _, opt := range opts {
_ = opt(cc)
}
}
func (cc *Options) GetSetOption(opt Option) Option {
return opt(cc)
}
type Option func(cc *Options) Option
func WithShards(v int32) Option {
return func(cc *Options) Option {
previous := cc.Shards
cc.Shards = v
return WithShards(previous)
}
}
func WithExpiration(v time.Duration) Option {
return func(cc *Options) Option {
previous := cc.Expiration
cc.Expiration = v
return WithExpiration(previous)
}
}
func WithEvictStrategy(v cache.EVICT_STRATEGY) Option {
return func(cc *Options) Option {
previous := cc.EvictStrategy
cc.EvictStrategy = v
return WithEvictStrategy(previous)
}
}
func WithCleanInterval(v time.Duration) Option {
return func(cc *Options) Option {
previous := cc.CleanInterval
cc.CleanInterval = v
return WithCleanInterval(previous)
}
}
func WithMaxEntrySize(v uint32) Option {
return func(cc *Options) Option {
previous := cc.MaxEntrySize
cc.MaxEntrySize = v
return WithMaxEntrySize(previous)
}
}
func WithHasher(v Hasher) Option {
return func(cc *Options) Option {
previous := cc.Hasher
cc.Hasher = v
return WithHasher(previous)
}
}
func WithOnRemoveCallbackFunc(v cache.EvictCallback) Option {
return func(cc *Options) Option {
previous := cc.OnRemoveCallbackFunc
cc.OnRemoveCallbackFunc = v
return WithOnRemoveCallbackFunc(previous)
}
}
func WithDevelopment(v bool) Option {
return func(cc *Options) Option {
previous := cc.Development
cc.Development = v
return WithDevelopment(previous)
}
}
func WithLogger(v Logger) Option {
return func(cc *Options) Option {
previous := cc.Logger
cc.Logger = v
return WithLogger(previous)
}
}
func NewOptions(opts ...Option) *Options {
cc := newDefaultOptions()
for _, opt := range opts {
_ = opt(cc)
}
if watchDogOptions != nil {
watchDogOptions(cc)
}
return cc
}
func InstallOptionsWatchDog(dog func(cc *Options)) {
watchDogOptions = dog
}
var watchDogOptions func(cc *Options)
func newDefaultOptions() *Options {
cc := &Options{}
for _, opt := range [...]Option{
WithShards(1024),
WithExpiration(DefaultExpiration),
WithEvictStrategy(default_evict_strategy),
WithCleanInterval(30 * time.Second),
WithMaxEntrySize(1024 * 1024),
WithHasher(newDefaultHasher()),
WithOnRemoveCallbackFunc(nil),
WithDevelopment(true),
WithLogger(nil),
} {
_ = opt(cc)
}
return cc
}