-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathregistry.go
50 lines (41 loc) · 955 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
45
46
47
48
49
50
package eventkit
import (
"context"
"time"
)
type Event struct {
Name string
Scope []string
Timestamp time.Time
Tags []Tag
}
type Destination interface {
Submit(...*Event)
Run(ctx context.Context)
}
type BatchDestination interface {
SubmitBatch(*[]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)
}
}