events
2015-07-15
Parent:e86251b04826
events/event.go
Create Publisher interface and stdout publisher. Create a Publisher interface that allows us to use different implementations and switch between them easily. The NSQ publisher already implements the interface, so it was really just copying that. Create an implmentation of the Publisher interface that just logs the data to stdout.
| paddy@0 | 1 package events |
| paddy@0 | 2 |
| paddy@0 | 3 import ( |
| paddy@0 | 4 "time" |
| paddy@0 | 5 ) |
| paddy@0 | 6 |
| paddy@1 | 7 const ( |
| paddy@1 | 8 ActionCreated = "created" |
| paddy@1 | 9 ActionUpdated = "updated" |
| paddy@1 | 10 ActionDeleted = "deleted" |
| paddy@1 | 11 ) |
| paddy@1 | 12 |
| paddy@0 | 13 type Event struct { |
| paddy@0 | 14 System string `json:"system"` |
| paddy@0 | 15 Model string `json:"model"` |
| paddy@0 | 16 ID string `json:"id"` |
| paddy@0 | 17 Action string `json:"action"` |
| paddy@0 | 18 Timestamp time.Time `json:"timestamp"` |
| paddy@1 | 19 Data interface{} `json:"data,omitempty"` |
| paddy@0 | 20 } |
| paddy@3 | 21 |
| paddy@3 | 22 type Publisher interface { |
| paddy@3 | 23 Publish(topic string, event Event) error |
| paddy@3 | 24 } |