github.com/mantzas/incata@v0.3.0/appender.go (about)

     1  package incata
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/mantzas/incata/model"
     7  	"github.com/mantzas/incata/writer"
     8  )
     9  
    10  // Appender interface
    11  type Appender interface {
    12  	Append(interface{}) error
    13  }
    14  
    15  // EventAppender Append events to storage
    16  type EventAppender struct {
    17  	Writer writer.Writer
    18  }
    19  
    20  var wr writer.Writer
    21  
    22  // SetupAppender setting up the appender
    23  func SetupAppender(writer writer.Writer) {
    24  	wr = writer
    25  }
    26  
    27  // NewAppender Creates a new event appender
    28  func NewAppender() (*EventAppender, error) {
    29  
    30  	if wr == nil {
    31  		return nil, errors.New("Writer is not set up!")
    32  	}
    33  	return &EventAppender{Writer: wr}, nil
    34  }
    35  
    36  // Append Append the payload to the storage
    37  func (appender *EventAppender) Append(event model.Event) error {
    38  
    39  	return appender.Writer.Write(event)
    40  }