This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
receiver.go
57 lines (46 loc) · 1.5 KB
/
receiver.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
package collector
import (
"context"
"github.com/fabric8-services/fabric8-notification/types"
)
type ReceiverResolver func(context.Context, string) (users []Receiver, templateValues map[string]interface{}, err error)
type ParamValidator func(context.Context, map[string]interface{}) error
type Receiver struct {
FullName string
EMail string
}
type Registry interface {
Register(types.NotificationType, ReceiverResolver, ParamValidator)
Get(types.NotificationType) (ReceiverResolver, bool)
Validator(types.NotificationType) (ParamValidator, bool)
Notifiers(types.NotificationType) []string
}
type localRegistry struct {
reg map[types.NotificationType]ReceiverResolver
validators map[types.NotificationType]ParamValidator
}
func NewRegistry() Registry {
return &localRegistry{
reg: map[types.NotificationType]ReceiverResolver{},
validators: map[types.NotificationType]ParamValidator{},
}
}
func (r *localRegistry) Get(nType types.NotificationType) (ReceiverResolver, bool) {
res, b := r.reg[nType]
return res, b
}
func (r *localRegistry) Validator(nType types.NotificationType) (ParamValidator, bool) {
v, found := r.validators[nType]
return v, found
}
func (r *localRegistry) Notifiers(nType types.NotificationType) []string {
return nType.Notifiers()
}
func (r *localRegistry) Register(nType types.NotificationType, resolver ReceiverResolver, validator ParamValidator) {
if resolver != nil {
r.reg[nType] = resolver
}
if validator != nil {
r.validators[nType] = validator
}
}