-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
60 lines (49 loc) · 1.51 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
package mgcache
import "time"
type (
// OptionFunc option function for IStorage
OptionFunc func(storageOption *StorageOption)
// StorageOption hold options for storage client
StorageOption struct {
codec ICodec
timeToLive time.Duration
contextTimeout time.Duration
// serviceIdentifier identifier for prometheus cacheBehaviorMetric
serviceIdentifier string
metricCollector IMetricCollector
}
)
const (
defaultServiceIdentifier = "mgcache"
)
// WithCodec customized codec for storage client
func WithCodec(c ICodec) OptionFunc {
return func(storageOption *StorageOption) {
storageOption.codec = c
}
}
// WithTimeToLive customized time-to-live for storage client
func WithTimeToLive(d time.Duration) OptionFunc {
return func(storageOption *StorageOption) {
storageOption.timeToLive = d
}
}
// WithContextTimeout customized context timeout for storage client
func WithContextTimeout(d time.Duration) OptionFunc {
return func(storageOption *StorageOption) {
storageOption.contextTimeout = d
}
}
// WithMetricCollector customized metric collector for storage client
// if not set, default metric collector defaultMetricCollector will be used
func WithMetricCollector(c IMetricCollector) OptionFunc {
return func(storageOption *StorageOption) {
storageOption.metricCollector = c
}
}
// WithServiceIdentifier customized service identifier for storage client
func WithServiceIdentifier(s string) OptionFunc {
return func(storageOption *StorageOption) {
storageOption.serviceIdentifier = s
}
}