-
Notifications
You must be signed in to change notification settings - Fork 25
/
basic-notifier.go
52 lines (43 loc) · 1.44 KB
/
basic-notifier.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
package notifiers
// NotifyFunc is a signature for basic notifier function.
type NotifyFunc func(Event)
// BasicKeyNotifier holds fields for basic key notifier.
type BasicKeyNotifier struct {
NotifyFunc NotifyFunc
KeyBase
}
// Make sure BasicKeyNotifier implements KeyNotifier.
var _ KeyNotifier = (*BasicKeyNotifier)(nil)
// NewBasicKeyNotifier returns a new basic key notifier.
func NewBasicKeyNotifier(key Key, notifyFunc NotifyFunc) *BasicKeyNotifier {
notifier := &BasicKeyNotifier{
KeyBase: NewKeyBase(key),
NotifyFunc: notifyFunc,
}
return notifier
}
// Notify calls the registered notifier function with the given event.
func (bfn *BasicKeyNotifier) Notify(event Event) {
if bfn.NotifyFunc != nil {
bfn.NotifyFunc(event)
}
}
// basicPrefixNotifier holds fields for basic prefix notifier.
type basicPrefixNotifier struct {
NotifyFunc NotifyFunc
PrefixBase
}
// Make sure BasicPrefixNotifier implements PrefixNotifier.
var _ PrefixNotifier = (*basicPrefixNotifier)(nil)
// GetKeyNotifier returns a basic key notifier for the given key.
func (bdn *basicPrefixNotifier) GetKeyNotifier(key Key) (KeyNotifier, error) {
return NewBasicKeyNotifier(key, bdn.NotifyFunc), nil
}
// NewBasicPrefixNotifier returns a new basic prefix notifier.
func NewBasicPrefixNotifier(prefix string, notifyFunc NotifyFunc) PrefixNotifier {
notifier := &basicPrefixNotifier{
PrefixBase: NewPrefixBase(prefix),
NotifyFunc: notifyFunc,
}
return notifier
}