-
Notifications
You must be signed in to change notification settings - Fork 39
/
event.go
52 lines (41 loc) · 1.19 KB
/
event.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 eventsource
import "time"
// Event describe a change that happened to the Aggregate
//
// * Past tense e.g. EmailChanged
// * Contains intent e.g. EmailChanged is better than EmailSet
type Event interface {
// AggregateID returns the id of the aggregate referenced by the event
AggregateID() string
// EventVersion contains the version number of this event
EventVersion() int
// EventAt indicates when the event occurred
EventAt() time.Time
}
// EventTyper is an optional interface that an Event can implement that allows it to specify an event type
// different than the name of the struct
type EventTyper interface {
// EventType returns the name of event type
EventType() string
}
// Model provides a default implementation of an Event
type Model struct {
// ID contains the AggregateID
ID string
// Version contains the EventVersion
Version int
// At contains the EventAt
At time.Time
}
// AggregateID implements the Event interface
func (m Model) AggregateID() string {
return m.ID
}
// EventVersion implements the Event interface
func (m Model) EventVersion() int {
return m.Version
}
// EventAt implements the Event interface
func (m Model) EventAt() time.Time {
return m.At
}