func (r *RecordWriter) processRecords() {
	for rec := range r.outputChan {
		for _, w := range r.OutputWriters {
			err := w(rec)
			if err != nil {
				log.Debugf("failed to write output %v: %s", rec, err)
			}
		}
	}
}
processRecords handles output processing in a goroutine
package flamingo
import (
	"sync"
	"time"
	log "github.com/sirupsen/logrus"
)
type OutputWriter func(map[string]string) error
type OutputCleaner func()
var OutputWriterNoOp = func(rec map[string]string) error {
	return nil
}
var OutputCleanerNoOp = func() {
	return
}
type RecordWriter struct {
	OutputWriters  []OutputWriter
	OutputCleaners []OutputCleaner
	outputChan     chan map[string]string
	outputChanOpen bool
	m              sync.Mutex
}
func NewRecordWriter() *RecordWriter {
	rw := &RecordWriter{
		outputChan:     make(chan map[string]string, 500),
		outputChanOpen: true,
	}
	go rw.processRecords()
	return rw
}
func (r *RecordWriter) Record(rtype string, proto string, source string, params map[string]string) {
	rec := make(map[string]string)
	rec["_etime"] = time.Now().Format(time.RFC3339)
	rec["_type"] = rtype
	rec["_host"] = source
	rec["_proto"] = proto
	for k, v := range params {
		if _, exists := rec[k]; exists {
			continue
		}
		rec[k] = v
	}
	r.m.Lock()
	defer r.m.Unlock()
	if !r.outputChanOpen {
		return
	}
	r.outputChan <- rec
}
func (r *RecordWriter) Done() {
	r.m.Lock()
	defer r.m.Unlock()
	if !r.outputChanOpen {
		return
	}
	r.outputChanOpen = false
	close(r.outputChan)
}