events
3:ce1212549d47 Browse Files
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.
1.1 --- a/event.go Tue Jul 14 00:05:45 2015 -0400 1.2 +++ b/event.go Wed Jul 15 00:19:41 2015 -0400 1.3 @@ -18,3 +18,7 @@ 1.4 Timestamp time.Time `json:"timestamp"` 1.5 Data interface{} `json:"data,omitempty"` 1.6 } 1.7 + 1.8 +type Publisher interface { 1.9 + Publish(topic string, event Event) error 1.10 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/stdout.go Wed Jul 15 00:19:41 2015 -0400 2.3 @@ -0,0 +1,18 @@ 2.4 +package events 2.5 + 2.6 +import ( 2.7 + "encoding/json" 2.8 + "os" 2.9 +) 2.10 + 2.11 +type StdoutPublisher struct{} 2.12 + 2.13 +func NewStdoutPublisher() StdoutPublisher { 2.14 + return StdoutPublisher{} 2.15 +} 2.16 + 2.17 +func (p StdoutPublisher) Publish(topic string, e Event) error { 2.18 + os.Stdout.Write([]byte(topic + ": ")) 2.19 + enc := json.NewEncoder(os.Stdout) 2.20 + return enc.Encode(e) 2.21 +}