-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathoptions.go
106 lines (89 loc) · 2.22 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
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
package rediswatcher
import (
"time"
"github.com/garyburd/redigo/redis"
)
type WatcherOptions struct {
Channel string
PubConn redis.Conn
SubConn redis.Conn
Username string
Password string
Protocol string
IgnoreSelf bool
LocalID string
RecordMetrics func(*WatcherMetrics)
SquashMessages bool
SquashTimeoutShort time.Duration
SquashTimeoutLong time.Duration
callbackPending bool
}
type WatcherOption func(*WatcherOptions)
func Channel(subject string) WatcherOption {
return func(options *WatcherOptions) {
options.Channel = subject
}
}
func Username(username string) WatcherOption {
return func(options *WatcherOptions) {
options.Username = username
}
}
func Password(password string) WatcherOption {
return func(options *WatcherOptions) {
options.Password = password
}
}
func Protocol(protocol string) WatcherOption {
return func(options *WatcherOptions) {
options.Protocol = protocol
}
}
func WithRedisSubConnection(connection redis.Conn) WatcherOption {
return func(options *WatcherOptions) {
options.SubConn = connection
}
}
func WithRedisPubConnection(connection redis.Conn) WatcherOption {
return func(options *WatcherOptions) {
options.PubConn = connection
}
}
func LocalID(id string) WatcherOption {
return func(options *WatcherOptions) {
options.LocalID = id
}
}
func IgnoreSelf(ignore bool) WatcherOption {
return func(options *WatcherOptions) {
options.IgnoreSelf = ignore
}
}
func SquashMessages(squash bool) WatcherOption {
return func(options *WatcherOptions) {
options.SquashMessages = squash
}
}
func RecordMetrics(callback func(*WatcherMetrics)) WatcherOption {
return func(options *WatcherOptions) {
options.RecordMetrics = callback
}
}
func SquashTimeoutShort(d time.Duration) WatcherOption {
return func(options *WatcherOptions) {
options.SquashTimeoutShort = d
}
}
func SquashTimeoutLong(d time.Duration) WatcherOption {
return func(options *WatcherOptions) {
options.SquashTimeoutLong = d
}
}
// IsCallbackPending
func IsCallbackPending(w *Watcher, shouldClear bool) bool {
r := w.options.callbackPending
if shouldClear {
w.options.callbackPending = false
}
return r
}