forked from storj/eventkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.go
44 lines (36 loc) · 855 Bytes
/
registry.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
package eventkit
import (
"time"
)
type Event struct {
Name string
Scope []string
Timestamp time.Time
Tags []Tag
}
type Destination interface {
Submit(*Event)
}
type Registry struct {
dests []Destination
}
func NewRegistry() *Registry { return &Registry{} }
func (r *Registry) Scope(name string) *Scope {
return &Scope{
r: r,
name: []string{name},
}
}
// AddDestination adds an output to the registry. Do not call
// AddDestination if (*Registry).Submit might be called
// concurrently. It is expected that AddDestination will be
// called at initialization time before any events.
func (r *Registry) AddDestination(dest Destination) {
r.dests = append(r.dests, dest)
}
// Submit submits an Event to all added Destinations.
func (r *Registry) Submit(e *Event) {
for _, dest := range r.dests {
dest.Submit(e)
}
}