-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.go
53 lines (40 loc) · 1.01 KB
/
events.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
package cqrs
import "github.com/satori/go.uuid"
type Event interface{}
type DomainEvent struct {
aggregateId uuid.UUID
id uuid.UUID
version int
event Event
}
type EventPublisher interface {
PublishEvent(event *DomainEvent) error
}
type EventHandler interface {
HandleEvent(*DomainEvent) error
}
func NewDomainEvent(
aggregateId uuid.UUID,
id uuid.UUID,
version int,
event Event,
) *DomainEvent {
return &DomainEvent{
aggregateId: aggregateId,
id: id,
version: version,
event: event,
}
}
func (e *DomainEvent) AggregateId() uuid.UUID { return e.aggregateId }
func (e *DomainEvent) Id() uuid.UUID { return e.id }
func (e *DomainEvent) Version() int { return e.version }
func (e *DomainEvent) Event() Event { return e.event }
type EventHandlerFunc func(*DomainEvent) error
func (f EventHandlerFunc) HandleEvent(evt *DomainEvent) error {
return f(evt)
}
type EventFactory interface {
CreateEvent(name string) (Event, error)
GetEventType(Event) (string, error)
}