-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
49 lines (41 loc) · 764 Bytes
/
opts.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
package locker
import "time"
type options struct {
ttl time.Duration
waitTTL time.Duration
key string
}
func newOptions() *options {
return &options{}
}
func (o *options) apply(opts ...Option) {
for _, opt := range opts {
opt(o)
}
}
func (o options) withOptions(opts ...Option) options {
o.apply(opts...)
return o
}
// WithTTL sets the TTL option.
func WithTTL(ttl time.Duration) Option {
return func(o *options) {
if ttl > 0 {
o.ttl = ttl
}
}
}
// WithWaitTTL sets the wait for receiving the lock TTL.
func WithWaitTTL(ttl time.Duration) Option {
return func(o *options) {
if ttl > 0 {
o.waitTTL = ttl
}
}
}
// WithKey sets the lock's key
func WithKey(key string) Option {
return func(o *options) {
o.key = key
}
}