Add tests and modify to work same as Kafka output

This commit is contained in:
Leonid Bugaev
2017-01-20 21:00:23 +03:00
6 changed files with 194 additions and 44 deletions
+10 -3
View File
@@ -3,21 +3,27 @@ package main
import (
"bytes"
"fmt"
"github.com/Shopify/sarama"
"github.com/buger/gor/proto"
)
// KafkaConfig should contains required information to
// build producers.
type KafkaConfig struct {
host string
topic string
host string
topic string
producer sarama.AsyncProducer
consumer sarama.Consumer
useJSON bool
}
// KafkaMessage should contains catched request information that should be
// passed as Json to Apache Kafka.
type KafkaMessage struct {
ReqURL string `json:"Req_URL"`
ReqType string `json:"Req_Type"`
ReqID string `json:"Req_ID"`
ReqTs string `json:"Req_Ts"`
ReqMethod string `json:"Req_Method"`
ReqBody string `json:"Req_Body,omitempty"`
ReqHeaders map[string]string `json:"Req_Headers,omitempty"`
@@ -28,6 +34,7 @@ type KafkaMessage struct {
func (m KafkaMessage) Dump() ([]byte, error) {
var b bytes.Buffer
b.WriteString(fmt.Sprintf("%s %s %s\n", m.ReqType, m.ReqID, m.ReqTs))
b.WriteString(fmt.Sprintf("%s %s HTTP/1.1", m.ReqMethod, m.ReqURL))
b.Write(proto.CLRF)
for key, value := range m.ReqHeaders {