-
Notifications
You must be signed in to change notification settings - Fork 17
/
options.go
43 lines (37 loc) · 868 Bytes
/
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
package lock
const (
unknown = "unknown"
)
type options struct {
// The pattern that was used to build to lock key
pattern string
// The method to provide context
method string
}
func buildOptions(opts ...Option) options {
os := options{
pattern: unknown,
method: unknown,
}
for _, opt := range opts {
opt(&os)
}
return os
}
// Option instances are used to provide optional arguments to
// the RuleLock.Lock method.
type Option func(lo *options)
// PatternForLock is used to specify the pattern that was used to
// build the lock key for metric tracking purposes.
func PatternForLock(pattern string) Option {
return func(lo *options) {
lo.pattern = pattern
}
}
// MethodForLock is used to specify the context in which the lock was
// obtained.
func MethodForLock(method string) Option {
return func(lo *options) {
lo.method = method
}
}