github.com/mantzas/incata@v0.3.0/retriever.go (about) 1 package incata 2 3 import ( 4 "errors" 5 "github.com/mantzas/incata/model" 6 "github.com/mantzas/incata/reader" 7 "github.com/satori/go.uuid" 8 ) 9 10 // Retriever interface 11 type Retriever interface { 12 Retrieve(uuid.UUID) ([]model.Event, error) 13 } 14 15 // EventRetriever Append events to storage 16 type EventRetriever struct { 17 Reader reader.Reader 18 } 19 20 var rd reader.Reader 21 22 // SetupRetriever setting up the retriever 23 func SetupRetriever(reader reader.Reader) { 24 rd = reader 25 } 26 27 // NewRetriever creates a new event retriever 28 func NewRetriever() (*EventRetriever, error) { 29 30 if rd == nil { 31 return nil, errors.New("Reader is not set up!") 32 } 33 return &EventRetriever{Reader: rd}, nil 34 } 35 36 // Retrieve events based on Source ID 37 func (appender *EventRetriever) Retrieve(sourceID uuid.UUID) ([]model.Event, error) { 38 39 return appender.Reader.Read(sourceID) 40 }