-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
65 lines (54 loc) · 1.37 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
57
58
59
60
61
62
63
64
65
package eventsource
import "reflect"
// Event ...
type Event interface {
GetAggregateID() string
GetUserID() string
GetSequenceID() string
GetTimestamp() int64
SetSequenceID(string)
SetTimestamp(int64)
}
// BaseEvent ...
type BaseEvent struct {
AggregateID string `json:"aggregateId"`
UserID string `json:"userId"`
SequenceID string `json:"sequenceId"`
Timestamp int64 `json:"timestamp"`
}
// GetType the type of the given input value, or if input is a pointer, return the type of the pointed to object
func GetType(e Event) reflect.Type {
value := reflect.TypeOf(e)
for value.Kind() == reflect.Ptr {
value = value.Elem()
}
return value
}
// GetTypeName the type of the given input value, or if input is a pointer, return the type of the pointed to object
func GetTypeName(e Event) string {
return GetType(e).Name()
}
// GetAggregateID ...
func (e BaseEvent) GetAggregateID() string {
return e.AggregateID
}
// GetUserID ...
func (e BaseEvent) GetUserID() string {
return e.UserID
}
// GetSequenceID ...
func (e BaseEvent) GetSequenceID() string {
return e.SequenceID
}
// GetTimestamp ...
func (e BaseEvent) GetTimestamp() int64 {
return e.Timestamp
}
// SetSequenceID ...
func (e *BaseEvent) SetSequenceID(sequenceID string) {
e.SequenceID = sequenceID
}
// SetTimestamp ...
func (e *BaseEvent) SetTimestamp(timestamp int64) {
e.Timestamp = timestamp
}