diff --git a/Makefile b/Makefile index 31e0b8c..f931492 100644 --- a/Makefile +++ b/Makefile @@ -31,19 +31,19 @@ vendor: go mod vendor release-bin-linux-amd64: vendor - docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) + docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/ release-bin-linux-arm64: vendor - docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) + docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/ release-bin-mac-amd64: vendor - GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) + GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) ./cmd/gor/ release-bin-mac-arm64: vendor GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) release-bin-windows: vendor - docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) build" -p "windows/amd64" + docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) build" -p "windows/amd64" ./cmd/gor/ mv $(BIN_NAME) "$(BIN_NAME).exe" release-linux-amd64: dist release-bin-linux-amd64 diff --git a/gor.go b/cmd/gor/gor.go similarity index 82% rename from gor.go rename to cmd/gor/gor.go index 0598b70..e1a30a6 100644 --- a/gor.go +++ b/cmd/gor/gor.go @@ -6,6 +6,7 @@ import ( "expvar" "flag" "fmt" + "github.com/buger/goreplay" "log" "net/http" "net/http/httputil" @@ -71,23 +72,23 @@ func main() { } args := os.Args[1:] - var plugins *InOutPlugins + var plugins *goreplay.InOutPlugins if len(args) > 0 && args[0] == "file-server" { if len(args) != 2 { log.Fatal("You should specify port and IP (optional) for the file server. Example: `gor file-server :80`") } dir, _ := os.Getwd() - Debug(0, "Started example file server for current directory on address ", args[1]) + goreplay.Debug(0, "Started example file server for current directory on address ", args[1]) log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(args[1], http.FileServer(http.Dir(dir))))) } else { flag.Parse() - checkSettings() - plugins = NewPlugins() + goreplay.CheckSettings() + plugins = goreplay.NewPlugins() } - log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), VERSION) + log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), goreplay.VERSION) if len(plugins.Inputs) == 0 || len(plugins.Outputs) == 0 { log.Fatal("Required at least 1 input and 1 output") @@ -101,20 +102,20 @@ func main() { profileCPU(*cpuprofile) } - if Settings.Pprof != "" { + if goreplay.Settings.Pprof != "" { go func() { - log.Println(http.ListenAndServe(Settings.Pprof, nil)) + log.Println(http.ListenAndServe(goreplay.Settings.Pprof, nil)) }() } closeCh := make(chan int) - emitter := NewEmitter() - go emitter.Start(plugins, Settings.Middleware) - if Settings.ExitAfter > 0 { - log.Printf("Running gor for a duration of %s\n", Settings.ExitAfter) + emitter := goreplay.NewEmitter() + go emitter.Start(plugins, goreplay.Settings.Middleware) + if goreplay.Settings.ExitAfter > 0 { + log.Printf("Running gor for a duration of %s\n", goreplay.Settings.ExitAfter) - time.AfterFunc(Settings.ExitAfter, func() { - log.Printf("gor run timeout %s\n", Settings.ExitAfter) + time.AfterFunc(goreplay.Settings.ExitAfter, func() { + log.Printf("gor run timeout %s\n", goreplay.Settings.ExitAfter) close(closeCh) }) } diff --git a/elasticsearch.go b/elasticsearch.go index 6914cc5..e979a40 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -1,14 +1,13 @@ -package main +package goreplay import ( "encoding/json" + "github.com/buger/goreplay/proto" "log" "net/url" "strings" "time" - "github.com/buger/goreplay/proto" - elastigo "github.com/mattbaird/elastigo/lib" ) diff --git a/elasticsearch_test.go b/elasticsearch_test.go index ef6bcac..77b8c0e 100644 --- a/elasticsearch_test.go +++ b/elasticsearch_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "testing" diff --git a/emitter.go b/emitter.go index 09625e9..6680c89 100644 --- a/emitter.go +++ b/emitter.go @@ -1,13 +1,13 @@ -package main +package goreplay import ( "fmt" + "github.com/buger/goreplay/internal/byteutils" "hash/fnv" "io" "log" "sync" - "github.com/buger/goreplay/byteutils" "github.com/coocood/freecache" ) diff --git a/emitter_test.go b/emitter_test.go index 805ce45..b95d701 100644 --- a/emitter_test.go +++ b/emitter_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "fmt" diff --git a/examples/middleware/token_modifier.go b/examples/middleware/token_modifier.go index 5367aba..b623483 100644 --- a/examples/middleware/token_modifier.go +++ b/examples/middleware/token_modifier.go @@ -24,9 +24,8 @@ import ( "bytes" "encoding/hex" "fmt" - "os" - "github.com/buger/goreplay/proto" + "os" ) // requestID -> originalToken diff --git a/gor_stat.go b/gor_stat.go index 1df7a9c..46ce358 100644 --- a/gor_stat.go +++ b/gor_stat.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "runtime" diff --git a/http_modifier.go b/http_modifier.go index 9575a17..859b403 100644 --- a/http_modifier.go +++ b/http_modifier.go @@ -1,12 +1,11 @@ -package main +package goreplay import ( "bytes" "encoding/base64" + "github.com/buger/goreplay/proto" "hash/fnv" "strings" - - "github.com/buger/goreplay/proto" ) type HTTPModifier struct { diff --git a/http_modifier_settings.go b/http_modifier_settings.go index 7edb50b..c773148 100644 --- a/http_modifier_settings.go +++ b/http_modifier_settings.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "errors" @@ -24,9 +24,7 @@ type HTTPModifierConfig struct { Methods HTTPMethods `json:"http-allow-method"` } -// // Handling of --http-allow-header, --http-disallow-header options -// type headerFilter struct { name []byte regexp *regexp.Regexp @@ -56,9 +54,7 @@ func (h *HTTPHeaderFilters) Set(value string) error { return nil } -// // Handling of --http-basic-auth-filter option -// type basicAuthFilter struct { regexp *regexp.Regexp } @@ -82,9 +78,7 @@ func (h *HTTPHeaderBasicAuthFilters) Set(value string) error { return nil } -// // Handling of --http-allow-header-hash and --http-allow-param-hash options -// type hashFilter struct { name []byte percent uint32 @@ -129,9 +123,7 @@ func (h *HTTPHashFilters) Set(value string) error { return nil } -// // Handling of --http-set-header option -// type httpHeader struct { Name string Value string @@ -160,9 +152,7 @@ func (h *HTTPHeaders) Set(value string) error { return nil } -// // Handling of --http-set-param option -// type httpParam struct { Name []byte Value []byte @@ -208,9 +198,7 @@ func (h *HTTPMethods) Set(value string) error { return nil } -// // Handling of --http-rewrite-url option -// type urlRewrite struct { src *regexp.Regexp target []byte @@ -237,9 +225,7 @@ func (r *URLRewriteMap) Set(value string) error { return nil } -// // Handling of --http-rewrite-header option -// type headerRewrite struct { header []byte src *regexp.Regexp @@ -275,9 +261,7 @@ func (r *HeaderRewriteMap) Set(value string) error { return nil } -// // Handling of --http-allow-url option -// type urlRegexp struct { regexp *regexp.Regexp } diff --git a/http_modifier_settings_test.go b/http_modifier_settings_test.go index e564a6e..03547fd 100644 --- a/http_modifier_settings_test.go +++ b/http_modifier_settings_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "testing" diff --git a/http_modifier_test.go b/http_modifier_test.go index e186f4a..e890248 100644 --- a/http_modifier_test.go +++ b/http_modifier_test.go @@ -1,10 +1,9 @@ -package main +package goreplay import ( "bytes" - "testing" - "github.com/buger/goreplay/proto" + "testing" ) func TestHTTPModifierWithoutConfig(t *testing.T) { diff --git a/http_prettifier.go b/http_prettifier.go index 0aefd37..596c6b2 100644 --- a/http_prettifier.go +++ b/http_prettifier.go @@ -1,14 +1,13 @@ -package main +package goreplay import ( "bytes" "compress/gzip" "fmt" + "github.com/buger/goreplay/proto" "io/ioutil" "net/http/httputil" "strconv" - - "github.com/buger/goreplay/proto" ) func prettifyHTTP(p []byte) []byte { diff --git a/http_prettifier_test.go b/http_prettifier_test.go index 7763a70..8bd30b7 100644 --- a/http_prettifier_test.go +++ b/http_prettifier_test.go @@ -1,12 +1,11 @@ -package main +package goreplay import ( "bytes" "compress/gzip" + "github.com/buger/goreplay/proto" "strconv" "testing" - - "github.com/buger/goreplay/proto" ) func TestHTTPPrettifierGzip(t *testing.T) { diff --git a/input_dummy.go b/input_dummy.go index cbf9586..cca7fe3 100644 --- a/input_dummy.go +++ b/input_dummy.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "time" diff --git a/input_file.go b/input_file.go index 643950e..feaf479 100644 --- a/input_file.go +++ b/input_file.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bufio" diff --git a/input_file_test.go b/input_file_test.go index 0538e62..59d057e 100644 --- a/input_file_test.go +++ b/input_file_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/input_http.go b/input_http.go index 46583b4..7ead5c8 100644 --- a/input_http.go +++ b/input_http.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "log" diff --git a/input_http_test.go b/input_http_test.go index afce748..873e096 100644 --- a/input_http_test.go +++ b/input_http_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/input_kafka.go b/input_kafka.go index ebd10ed..a4c2fa2 100644 --- a/input_kafka.go +++ b/input_kafka.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "encoding/json" diff --git a/input_kafka_test.go b/input_kafka_test.go index 3ae6974..d632cf8 100644 --- a/input_kafka_test.go +++ b/input_kafka_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "testing" diff --git a/input_raw.go b/input_raw.go index 63eb4b4..a3de66f 100644 --- a/input_raw.go +++ b/input_raw.go @@ -1,17 +1,16 @@ -package main +package goreplay import ( "context" "fmt" + "github.com/buger/goreplay/internal/capture" + "github.com/buger/goreplay/internal/tcp" + "github.com/buger/goreplay/proto" "log" "net" "strconv" "strings" "sync" - - "github.com/buger/goreplay/capture" - "github.com/buger/goreplay/proto" - "github.com/buger/goreplay/tcp" ) // RAWInputConfig represents configuration that can be applied on raw input diff --git a/input_raw_test.go b/input_raw_test.go index 52d5760..cf5e667 100644 --- a/input_raw_test.go +++ b/input_raw_test.go @@ -1,7 +1,10 @@ -package main +package goreplay import ( "bytes" + "github.com/buger/goreplay/internal/capture" + "github.com/buger/goreplay/internal/tcp" + "github.com/buger/goreplay/proto" "io/ioutil" "net" "net/http" @@ -13,10 +16,6 @@ import ( "sync/atomic" "testing" "time" - - "github.com/buger/goreplay/capture" - "github.com/buger/goreplay/proto" - "github.com/buger/goreplay/tcp" ) const testRawExpire = time.Millisecond * 200 diff --git a/input_tcp.go b/input_tcp.go index 257bc12..e31217c 100644 --- a/input_tcp.go +++ b/input_tcp.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bufio" diff --git a/input_tcp_test.go b/input_tcp_test.go index 7714ce3..543b0d0 100644 --- a/input_tcp_test.go +++ b/input_tcp_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/byteutils/byteutils.go b/internal/byteutils/byteutils.go similarity index 100% rename from byteutils/byteutils.go rename to internal/byteutils/byteutils.go diff --git a/byteutils/byteutils_test.go b/internal/byteutils/byteutils_test.go similarity index 100% rename from byteutils/byteutils_test.go rename to internal/byteutils/byteutils_test.go diff --git a/capture/af_packet.go b/internal/capture/af_packet.go similarity index 100% rename from capture/af_packet.go rename to internal/capture/af_packet.go diff --git a/capture/af_packet_linux.go b/internal/capture/af_packet_linux.go similarity index 100% rename from capture/af_packet_linux.go rename to internal/capture/af_packet_linux.go diff --git a/capture/capture.go b/internal/capture/capture.go similarity index 98% rename from capture/capture.go rename to internal/capture/capture.go index 8175b1a..b2a31f1 100644 --- a/capture/capture.go +++ b/internal/capture/capture.go @@ -5,6 +5,9 @@ import ( "errors" "expvar" "fmt" + "github.com/buger/goreplay/internal/size" + "github.com/buger/goreplay/internal/tcp" + "github.com/buger/goreplay/proto" "io" "log" "net" @@ -15,10 +18,6 @@ import ( "syscall" "time" - "github.com/buger/goreplay/proto" - "github.com/buger/goreplay/size" - "github.com/buger/goreplay/tcp" - "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/google/gopacket/pcap" @@ -286,11 +285,12 @@ func (l *Listener) ListenBackground(ctx context.Context) chan error { } // Allowed format: -// [namespace/]pod/[pod_name] -// [namespace/]deployment/[deployment_name] -// [namespace/]daemonset/[daemonset_name] -// [namespace/]labelSelector/[selector] -// [namespace/]fieldSelector/[selector] +// +// [namespace/]pod/[pod_name] +// [namespace/]deployment/[deployment_name] +// [namespace/]daemonset/[daemonset_name] +// [namespace/]labelSelector/[selector] +// [namespace/]fieldSelector/[selector] func k8sIPs(addr string) []string { config, err := rest.InClusterConfig() if err != nil { diff --git a/capture/capture_test.go b/internal/capture/capture_test.go similarity index 100% rename from capture/capture_test.go rename to internal/capture/capture_test.go diff --git a/capture/doc.go b/internal/capture/doc.go similarity index 82% rename from capture/doc.go rename to internal/capture/doc.go index 65c05e4..185c370 100644 --- a/capture/doc.go +++ b/internal/capture/doc.go @@ -9,27 +9,34 @@ example: // for the transport should be "tcp" listener, err := capture.NewListener(host, port, transport, engine, trackResponse) -if err != nil { - // handle error -} + + if err != nil { + // handle error + } + listener.SetPcapOptions(opts) err = listner.Activate() -if err != nil { - // handle it -} -if err := listener.Listen(context.Background(), handler); err != nil { - // handle error -} + if err != nil { + // handle it + } + + if err := listener.Listen(context.Background(), handler); err != nil { + // handle error + } + // or errCh := listener.ListenBackground(context.Background(), handler) // runs in the background select { case err := <- errCh: + // handle error + case <-quit: + // + case <- l.Reading: // if we have started reading } - */ package capture // import github.com/buger/goreplay/capture diff --git a/capture/dump.go b/internal/capture/dump.go similarity index 76% rename from capture/dump.go rename to internal/capture/dump.go index a4974f2..ff589a9 100644 --- a/capture/dump.go +++ b/internal/capture/dump.go @@ -35,18 +35,18 @@ const versionMinor = 4 // an append), you must call WriteFileHeader before WritePacket. Packet // timestamps are written with nanosecond precision. // -// // Write a new file: -// f, _ := os.Create("/tmp/file.pcap") -// w := pcapgo.NewWriterNanos(f) -// w.WriteFileHeader(65536, layers.LinkTypeEthernet) // new file, must do this. -// w.WritePacket(gopacket.CaptureInfo{...}, data1) -// f.Close() -// // Append to existing file (must have same snaplen and linktype) -// f2, _ := os.OpenFile("/tmp/fileNano.pcap", os.O_APPEND, 0700) -// w2 := pcapgo.NewWriter(f2) -// // no need for file header, it's already written. -// w2.WritePacket(gopacket.CaptureInfo{...}, data2) -// f2.Close() +// // Write a new file: +// f, _ := os.Create("/tmp/file.pcap") +// w := pcapgo.NewWriterNanos(f) +// w.WriteFileHeader(65536, layers.LinkTypeEthernet) // new file, must do this. +// w.WritePacket(gopacket.CaptureInfo{...}, data1) +// f.Close() +// // Append to existing file (must have same snaplen and linktype) +// f2, _ := os.OpenFile("/tmp/fileNano.pcap", os.O_APPEND, 0700) +// w2 := pcapgo.NewWriter(f2) +// // no need for file header, it's already written. +// w2.WritePacket(gopacket.CaptureInfo{...}, data2) +// f2.Close() func NewWriterNanos(w io.Writer) *Writer { return &Writer{w: w, tsScaler: nanosPerNano} } @@ -56,18 +56,18 @@ func NewWriterNanos(w io.Writer) *Writer { // an append), you must call WriteFileHeader before WritePacket. // Packet timestamps are written with microsecond precision. // -// // Write a new file: -// f, _ := os.Create("/tmp/file.pcap") -// w := pcapgo.NewWriter(f) -// w.WriteFileHeader(65536, layers.LinkTypeEthernet) // new file, must do this. -// w.WritePacket(gopacket.CaptureInfo{...}, data1) -// f.Close() -// // Append to existing file (must have same snaplen and linktype) -// f2, _ := os.OpenFile("/tmp/file.pcap", os.O_APPEND, 0700) -// w2 := pcapgo.NewWriter(f2) -// // no need for file header, it's already written. -// w2.WritePacket(gopacket.CaptureInfo{...}, data2) -// f2.Close() +// // Write a new file: +// f, _ := os.Create("/tmp/file.pcap") +// w := pcapgo.NewWriter(f) +// w.WriteFileHeader(65536, layers.LinkTypeEthernet) // new file, must do this. +// w.WritePacket(gopacket.CaptureInfo{...}, data1) +// f.Close() +// // Append to existing file (must have same snaplen and linktype) +// f2, _ := os.OpenFile("/tmp/file.pcap", os.O_APPEND, 0700) +// w2 := pcapgo.NewWriter(f2) +// // no need for file header, it's already written. +// w2.WritePacket(gopacket.CaptureInfo{...}, data2) +// f2.Close() func NewWriter(w io.Writer) *Writer { return &Writer{w: w, tsScaler: nanosPerMicro} } diff --git a/capture/sock_linux.go b/internal/capture/sock_linux.go similarity index 100% rename from capture/sock_linux.go rename to internal/capture/sock_linux.go diff --git a/capture/sock_others.go b/internal/capture/sock_others.go similarity index 100% rename from capture/sock_others.go rename to internal/capture/sock_others.go diff --git a/capture/socket.go b/internal/capture/socket.go similarity index 100% rename from capture/socket.go rename to internal/capture/socket.go diff --git a/capture/vxlan.go b/internal/capture/vxlan.go similarity index 100% rename from capture/vxlan.go rename to internal/capture/vxlan.go diff --git a/ring/ring.go b/internal/ring/ring.go similarity index 100% rename from ring/ring.go rename to internal/ring/ring.go diff --git a/simpletime/time.go b/internal/simpletime/time.go similarity index 100% rename from simpletime/time.go rename to internal/simpletime/time.go diff --git a/size/size.go b/internal/size/size.go similarity index 100% rename from size/size.go rename to internal/size/size.go diff --git a/size/size_test.go b/internal/size/size_test.go similarity index 100% rename from size/size_test.go rename to internal/size/size_test.go diff --git a/tcp/doc.go b/internal/tcp/doc.go similarity index 99% rename from tcp/doc.go rename to internal/tcp/doc.go index 61551c9..cbae155 100644 --- a/tcp/doc.go +++ b/internal/tcp/doc.go @@ -4,7 +4,6 @@ parsing, reassembling tcp packets, handling communication with engine listeners( and reporting errors and statistics of packets. the packets are parsed by following TCP way(https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure). - example: import "github.com/buger/goreplay/tcp" @@ -22,6 +21,5 @@ you can use pool.End or/and pool.Start to set custom session behaviors debugLevel in debugger function indicates the priority of the logs, the bigger the number the lower the priority. errors are signified by debug level 4 for errors, 5 for discarded packets, and 6 for received packets. - */ package tcp // import github.com/buger/goreplay/tcp diff --git a/tcp/tcp_message.go b/internal/tcp/tcp_message.go similarity index 99% rename from tcp/tcp_message.go rename to internal/tcp/tcp_message.go index b52f0e6..e2a2188 100644 --- a/tcp/tcp_message.go +++ b/internal/tcp/tcp_message.go @@ -4,13 +4,12 @@ import ( "encoding/binary" "encoding/hex" "fmt" + "github.com/buger/goreplay/proto" "net" "reflect" "sort" "time" "unsafe" - - "github.com/buger/goreplay/proto" ) // TCPProtocol is a number to indicate type of protocol @@ -350,7 +349,7 @@ func (parser *MessageParser) processPacket(pckt *Packet) { m.DstAddr = pckt.DstIP.String() parser.m[pckt.MessageID()] = m - + m.Start = pckt.Timestamp m.parser = parser parser.addPacket(m, pckt) diff --git a/tcp/tcp_packet.go b/internal/tcp/tcp_packet.go similarity index 100% rename from tcp/tcp_packet.go rename to internal/tcp/tcp_packet.go diff --git a/tcp/tcp_test.go b/internal/tcp/tcp_test.go similarity index 100% rename from tcp/tcp_test.go rename to internal/tcp/tcp_test.go index 363657c..e820d9c 100644 --- a/tcp/tcp_test.go +++ b/internal/tcp/tcp_test.go @@ -3,6 +3,7 @@ package tcp import ( "bytes" "encoding/binary" + "github.com/buger/goreplay/proto" // "runtime" "testing" @@ -10,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" - "github.com/buger/goreplay/proto" "github.com/google/gopacket" "github.com/google/gopacket/layers" ) diff --git a/kafka.go b/kafka.go index a73a812..f149770 100644 --- a/kafka.go +++ b/kafka.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" @@ -8,11 +8,11 @@ import ( "crypto/x509" "errors" "fmt" + "github.com/buger/goreplay/proto" "io/ioutil" "log" "github.com/Shopify/sarama" - "github.com/buger/goreplay/proto" "github.com/xdg-go/scram" ) diff --git a/limiter.go b/limiter.go index 2d89f8b..7ee4854 100644 --- a/limiter.go +++ b/limiter.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "fmt" diff --git a/limiter_test.go b/limiter_test.go index 62a0f7c..6408dd2 100644 --- a/limiter_test.go +++ b/limiter_test.go @@ -1,6 +1,6 @@ //go:build !race -package main +package goreplay import ( "sync" diff --git a/middleware.go b/middleware.go index 5f775a4..740b813 100644 --- a/middleware.go +++ b/middleware.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bufio" diff --git a/middleware_test.go b/middleware_test.go index 7c67d0b..cf9807a 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/output_binary.go b/output_binary.go index 32b3e3a..7f77573 100644 --- a/output_binary.go +++ b/output_binary.go @@ -1,10 +1,9 @@ -package main +package goreplay import ( + "github.com/buger/goreplay/internal/size" "sync/atomic" "time" - - "github.com/buger/goreplay/size" ) // BinaryOutputConfig struct for holding binary output configuration diff --git a/output_dummy.go b/output_dummy.go index 3d67a59..32ab794 100644 --- a/output_dummy.go +++ b/output_dummy.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "os" diff --git a/output_file.go b/output_file.go index c8dd576..4b5a040 100644 --- a/output_file.go +++ b/output_file.go @@ -1,10 +1,11 @@ -package main +package goreplay import ( "bufio" "compress/gzip" "errors" "fmt" + "github.com/buger/goreplay/internal/size" "io" "log" "math/rand" @@ -16,8 +17,6 @@ import ( "strings" "sync" "time" - - "github.com/buger/goreplay/size" ) var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") diff --git a/output_file_test.go b/output_file_test.go index 850921a..65d0cf7 100644 --- a/output_file_test.go +++ b/output_file_test.go @@ -1,7 +1,8 @@ -package main +package goreplay import ( "fmt" + "github.com/buger/goreplay/internal/size" "math/rand" "os" "reflect" @@ -10,8 +11,6 @@ import ( "sync/atomic" "testing" "time" - - "github.com/buger/goreplay/size" ) func TestFileOutput(t *testing.T) { diff --git a/output_http.go b/output_http.go index 830db46..7ba57c8 100644 --- a/output_http.go +++ b/output_http.go @@ -1,10 +1,11 @@ -package main +package goreplay import ( "bufio" "bytes" "crypto/tls" "fmt" + "github.com/buger/goreplay/internal/size" "log" "math" "net/http" @@ -12,8 +13,6 @@ import ( "net/url" "sync/atomic" "time" - - "github.com/buger/goreplay/size" ) const ( diff --git a/output_http_test.go b/output_http_test.go index 91ec5b7..d884609 100644 --- a/output_http_test.go +++ b/output_http_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "io/ioutil" diff --git a/output_kafka.go b/output_kafka.go index 5398b79..faa5051 100644 --- a/output_kafka.go +++ b/output_kafka.go @@ -1,14 +1,13 @@ -package main +package goreplay import ( "encoding/json" + "github.com/buger/goreplay/internal/byteutils" + "github.com/buger/goreplay/proto" "log" "strings" "time" - "github.com/buger/goreplay/byteutils" - "github.com/buger/goreplay/proto" - "github.com/Shopify/sarama" "github.com/Shopify/sarama/mocks" ) diff --git a/output_kafka_test.go b/output_kafka_test.go index b7227c6..b448161 100644 --- a/output_kafka_test.go +++ b/output_kafka_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "testing" diff --git a/output_null.go b/output_null.go index 0957ed9..9d12332 100644 --- a/output_null.go +++ b/output_null.go @@ -1,4 +1,4 @@ -package main +package goreplay // NullOutput used for debugging, prints nothing type NullOutput struct { diff --git a/output_s3.go b/output_s3.go index cdebfbf..2cd5754 100644 --- a/output_s3.go +++ b/output_s3.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( _ "bufio" diff --git a/output_tcp.go b/output_tcp.go index 5be0d7c..2a3680c 100644 --- a/output_tcp.go +++ b/output_tcp.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "context" diff --git a/output_tcp_test.go b/output_tcp_test.go index 803601a..8a860b1 100644 --- a/output_tcp_test.go +++ b/output_tcp_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bufio" diff --git a/output_ws.go b/output_ws.go index be7d33b..3f2a102 100644 --- a/output_ws.go +++ b/output_ws.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "context" diff --git a/output_ws_test.go b/output_ws_test.go index ffce5b0..c80314d 100644 --- a/output_ws_test.go +++ b/output_ws_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "github.com/gorilla/websocket" diff --git a/plugins.go b/plugins.go index be2aab3..d37b683 100644 --- a/plugins.go +++ b/plugins.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "reflect" diff --git a/plugins_test.go b/plugins_test.go index e4b0c33..7e50d23 100644 --- a/plugins_test.go +++ b/plugins_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "testing" diff --git a/pro.go b/pro.go index e4f73be..b06b1f9 100644 --- a/pro.go +++ b/pro.go @@ -1,4 +1,4 @@ -package main +package goreplay // PRO this value indicates if goreplay is running in PRO mode.. // it must not be modified explicitly in production diff --git a/proto/fuzz.go b/proto/fuzz.go index e257940..8521391 100644 --- a/proto/fuzz.go +++ b/proto/fuzz.go @@ -1,4 +1,4 @@ -// +build gofuzz +//go:build gofuzz package proto diff --git a/proto/proto.go b/proto/proto.go index 4bbae23..1c3abe6 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -19,13 +19,12 @@ package proto import ( "bufio" "bytes" + "github.com/buger/goreplay/internal/byteutils" _ "fmt" "net/http" "net/textproto" "strings" - - "github.com/buger/goreplay/byteutils" ) // CRLF In HTTP newline defined by 2 bytes (for both windows and *nix support) diff --git a/protocol.go b/protocol.go index e1d4a00..fc9b905 100644 --- a/protocol.go +++ b/protocol.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/s3_reader.go b/s3_reader.go index 5a26b83..e485cff 100644 --- a/s3_reader.go +++ b/s3_reader.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "bytes" diff --git a/s3_test.go b/s3_test.go index acd517d..218ef91 100644 --- a/s3_test.go +++ b/s3_test.go @@ -1,6 +1,6 @@ //go:build pro -package main +package goreplay import ( "fmt" diff --git a/settings.go b/settings.go index 6bb032f..884803e 100644 --- a/settings.go +++ b/settings.go @@ -1,14 +1,13 @@ -package main +package goreplay import ( "flag" "fmt" + "github.com/buger/goreplay/internal/size" "os" "strconv" "sync" "time" - - "github.com/buger/goreplay/size" ) // DEMO indicates that goreplay is running in demo mode @@ -276,7 +275,7 @@ func init() { } -func checkSettings() { +func CheckSettings() { if Settings.OutputFileConfig.SizeLimit < 1 { Settings.OutputFileConfig.SizeLimit.Set("32mb") } diff --git a/settings_test.go b/settings_test.go index 2f62d2d..7d797fb 100644 --- a/settings_test.go +++ b/settings_test.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "encoding/json" diff --git a/tcp_client.go b/tcp_client.go index 981a58d..156ffca 100644 --- a/tcp_client.go +++ b/tcp_client.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "crypto/tls" diff --git a/test_input.go b/test_input.go index 954ccef..64e47a2 100644 --- a/test_input.go +++ b/test_input.go @@ -1,4 +1,4 @@ -package main +package goreplay import ( "encoding/base64" diff --git a/test_output.go b/test_output.go index 0452d42..82c1301 100644 --- a/test_output.go +++ b/test_output.go @@ -1,4 +1,4 @@ -package main +package goreplay type writeCallback func(*Message) diff --git a/version.go b/version.go index 68c502d..cd44958 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ -package main +package goreplay // VERSION the current version of goreplay var VERSION = "1.3.0"