-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
91 lines (71 loc) · 1.57 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package entropy
import (
"time"
)
type ChangeEvent interface {
Id() string
}
type TombstoneEvent interface {
ChangeEvent
}
type UpsertEvent interface {
ChangeEvent
Version() string
}
type UnpartitionedEvent interface {
UpsertEvent
IdHierarchy() *MerkleNode
}
type PartitionedEvent interface {
UnpartitionedEvent
Attributes() map[string]string
AttributeHierarchy() *MerkleNode
}
type baseChangeEvent struct {
id string
}
type baseUpsertEvent struct {
baseChangeEvent
version string
}
type baseUnpartitionedEvent struct {
baseUpsertEvent
idHierarchy *MerkleNode
}
type basePartitionedEvent struct {
baseUnpartitionedEvent
attributeHierarchy *MerkleNode
attributes map[string]string
}
func (d *basePartitionedEvent) Id() string {
return d.id
}
func (d *basePartitionedEvent) Version() string {
return d.version
}
func (d *basePartitionedEvent) IdHierarchy() *MerkleNode {
return d.idHierarchy
}
func (d *basePartitionedEvent) Attributes() map[string]string {
return d.attributes
}
func (d *basePartitionedEvent) AttributeHierarchy() *MerkleNode {
return d.attributeHierarchy
}
const (
dateFormat = "20060102150405"
yearFormat = "2006"
monthFormat = "01"
dayFormat = "02"
)
func NewDatePartitionedEvent(id, version, attributeName string, d time.Time) PartitionedEvent {
atts := make(map[string]string)
atts[attributeName] = d.Format(dateFormat)
ev := &basePartitionedEvent{}
ev.attributes = atts
ev.id = id
ev.version = version
ev.idHierarchy = BuildEntityNode(id, version)
ev.attributeHierarchy = BuildDateTimeNode(id, version, d)
return ev
}