events

Paddy 2015-07-15 Parent:ce1212549d47

4:2d030022b4b5 Go to Latest

events/event.go

Create our Model helper. Create a Model interface that any type can implement by just providing getters that will be used to build Events produced around that type. Add a PublishModelEvent helper that takes a Publisher, a Model, and an action (as a string) and builds a consistent Event around the Model, then publishes it to the Publisher. This is a helpful wrapper in most of our systems, and will probably handle 99% of our NSQ publishes, because most of our infrastructure is going to be something like "a new profile was created" or "a new login was created" or "a profile was updated" and we just want to disseminate that information across all our services, to push based on it, or trigger actions. This abstracts it out nicely to a standard format and a nice, easy way to send those messages.

History
1 package events
3 import (
4 "time"
5 )
7 const (
8 ActionCreated = "created"
9 ActionUpdated = "updated"
10 ActionDeleted = "deleted"
11 )
13 type Event struct {
14 System string `json:"system"`
15 Model string `json:"model"`
16 ID string `json:"id"`
17 Action string `json:"action"`
18 Timestamp time.Time `json:"timestamp"`
19 Data interface{} `json:"data,omitempty"`
20 }
22 type Publisher interface {
23 Publish(topic string, event Event) error
24 }