mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Add tests and modify to work same as Kafka output
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user