Skip to content
Brandon Piner edited this page Aug 19, 2018 · 2 revisions

Defining Events

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"
)

Events With No Data

The event InviteAcceptedEvent does not require any additional data. For events like this, no further definitions are required.

Events With Data

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

Clone this wiki locally