gitlab.com/beacon-software/gadget@v0.0.0-20181217202115-54565ea1ed5e/log/cloudwatch/eventqueue.go (about) 1 package cloudwatch 2 3 import ( 4 "github.com/aws/aws-sdk-go/service/cloudwatchlogs" 5 6 "gitlab.com/beacon-software/gadget/collection" 7 ) 8 9 // EventQueue for buffering cloud watch events. 10 type EventQueue interface { 11 // Size of this queue 12 Size() int 13 // Push the passed event onto this queue 14 Push(event *cloudwatchlogs.InputLogEvent) 15 // Pop the last event pushed off this queue 16 Pop() (*cloudwatchlogs.InputLogEvent, error) 17 // Peek at the next event that will be popped. 18 Peek() (*cloudwatchlogs.InputLogEvent, error) 19 } 20 21 type eventQueue struct { 22 queue collection.Queue 23 } 24 25 // NewEventQueue that is empty. 26 func NewEventQueue() EventQueue { 27 return &eventQueue{queue: collection.NewQueue()} 28 } 29 30 func (eq *eventQueue) Size() int { 31 return eq.queue.Size() 32 } 33 34 func (eq *eventQueue) Push(event *cloudwatchlogs.InputLogEvent) { 35 eq.queue.Push(event) 36 } 37 38 func (eq *eventQueue) Pop() (*cloudwatchlogs.InputLogEvent, error) { 39 obj, err := eq.queue.Pop() 40 if nil != err { 41 return nil, err 42 } 43 event, _ := obj.(*cloudwatchlogs.InputLogEvent) 44 return event, nil 45 } 46 47 func (eq *eventQueue) Peek() (*cloudwatchlogs.InputLogEvent, error) { 48 obj, err := eq.queue.Peek() 49 if nil != err { 50 return nil, err 51 } 52 event, _ := obj.(*cloudwatchlogs.InputLogEvent) 53 return event, nil 54 }