-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathevents.go
68 lines (56 loc) · 1.13 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
package main
import (
uuid "github.com/satori/go.uuid"
)
/* each event expressed as its own struct */
type Event struct {
AccId string
Type string
}
type CreateEvent struct {
Event
AccName string
}
type DepositEvent struct {
Event
Amount int
}
type WithdrawEvent struct {
Event
Amount int
}
type TransferEvent struct {
Event
TargetId string
Amount int
}
/* helper to create events */
func NewCreateAccountEvent(name string) CreateEvent {
event := new(CreateEvent)
event.Type = "CreateEvent"
event.AccId = uuid.NewV4().String()
event.AccName = name
return *event
}
func NewDepositEvent(id string, amt int) DepositEvent {
event := new(DepositEvent)
event.Type = "DepositEvent"
event.AccId = id
event.Amount = amt
return *event
}
func NewWithdrawEvent(id string, amt int) WithdrawEvent {
event := new(WithdrawEvent)
event.Type = "WithdrawEvent"
event.AccId = id
event.Amount = amt
return *event
}
func NewTransferEvent(id string, targetId string, amt int) TransferEvent {
event := new(TransferEvent)
event.Type = "TransferEvent"
event.AccId = id
event.Amount = amt
event.TargetId = targetId
return *event
}