-
Notifications
You must be signed in to change notification settings - Fork 196
Events
Brandon Piner edited this page Aug 19, 2018
·
2 revisions
You can define all of your events in a single file called events.go
. Begin by defining all of the events as a const:
const (
InviteCreatedEvent eh.EventType = "InviteCreated"
InviteAcceptedEvent eh.EventType = "InviteAccepted"
)
The event InviteAcceptedEvent does not require any additional data. For events like this, no further definitions are required.
If an event has to carry additional data then you have to define and register a struct for that data.
You can define the data in the same events.go
file:
type InviteCreatedData struct {
Name string `bson:"name"`
Age int `bson:"age"`
}
and register it to the InviteCreatedEvent in the init():
func init() {
eh.RegisterEventData(InviteCreatedEvent, func() eh.EventData {
return &InviteCreatedData{}
})
}
Taken from the example file