forked from hallgren/eventsourcing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
56 lines (43 loc) · 1.05 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
53
54
55
56
package eventsourcing
import (
"reflect"
"time"
"github.com/hallgren/eventsourcing/core"
)
// Version is the event version used in event.Version and event.GlobalVersion
type Version core.Version
type Event struct {
event core.Event // internal event
data interface{}
metadata map[string]interface{}
}
func NewEvent(e core.Event, data interface{}, metadata map[string]interface{}) Event {
return Event{event: e, data: data, metadata: metadata}
}
func (e Event) Data() interface{} {
return e.data
}
func (e Event) Metadata() map[string]interface{} {
return e.metadata
}
func (e Event) AggregateType() string {
return e.event.AggregateType
}
func (e Event) AggregateID() string {
return e.event.AggregateID
}
func (e Event) Reason() string {
if e.data == nil {
return ""
}
return reflect.TypeOf(e.data).Elem().Name()
}
func (e Event) Version() Version {
return Version(e.event.Version)
}
func (e Event) Timestamp() time.Time {
return e.event.Timestamp
}
func (e Event) GlobalVersion() Version {
return Version(e.event.GlobalVersion)
}