Skip to content

Commit 4094683

Browse files
authored
goreplay-cli package (#1148)
change package from `main -> goreplay` this will allow importing `goreplay` as a package
1 parent 99e6fdf commit 4094683

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+148
-174
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ vendor:
3131
go mod vendor
3232

3333
release-bin-linux-amd64: vendor
34-
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)
34+
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/
3535

3636
release-bin-linux-arm64: vendor
37-
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)
37+
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/
3838

3939
release-bin-mac-amd64: vendor
40-
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS)
40+
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) ./cmd/gor/
4141

4242
release-bin-mac-arm64: vendor
4343
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS)
4444

4545
release-bin-windows: vendor
46-
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"
46+
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/
4747
mv $(BIN_NAME) "$(BIN_NAME).exe"
4848

4949
release-linux-amd64: dist release-bin-linux-amd64

gor.go renamed to cmd/gor/gor.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"expvar"
77
"flag"
88
"fmt"
9+
"github.com/buger/goreplay"
910
"log"
1011
"net/http"
1112
"net/http/httputil"
@@ -71,23 +72,23 @@ func main() {
7172
}
7273

7374
args := os.Args[1:]
74-
var plugins *InOutPlugins
75+
var plugins *goreplay.InOutPlugins
7576
if len(args) > 0 && args[0] == "file-server" {
7677
if len(args) != 2 {
7778
log.Fatal("You should specify port and IP (optional) for the file server. Example: `gor file-server :80`")
7879
}
7980
dir, _ := os.Getwd()
8081

81-
Debug(0, "Started example file server for current directory on address ", args[1])
82+
goreplay.Debug(0, "Started example file server for current directory on address ", args[1])
8283

8384
log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(args[1], http.FileServer(http.Dir(dir)))))
8485
} else {
8586
flag.Parse()
86-
checkSettings()
87-
plugins = NewPlugins()
87+
goreplay.CheckSettings()
88+
plugins = goreplay.NewPlugins()
8889
}
8990

90-
log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), VERSION)
91+
log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), goreplay.VERSION)
9192

9293
if len(plugins.Inputs) == 0 || len(plugins.Outputs) == 0 {
9394
log.Fatal("Required at least 1 input and 1 output")
@@ -101,20 +102,20 @@ func main() {
101102
profileCPU(*cpuprofile)
102103
}
103104

104-
if Settings.Pprof != "" {
105+
if goreplay.Settings.Pprof != "" {
105106
go func() {
106-
log.Println(http.ListenAndServe(Settings.Pprof, nil))
107+
log.Println(http.ListenAndServe(goreplay.Settings.Pprof, nil))
107108
}()
108109
}
109110

110111
closeCh := make(chan int)
111-
emitter := NewEmitter()
112-
go emitter.Start(plugins, Settings.Middleware)
113-
if Settings.ExitAfter > 0 {
114-
log.Printf("Running gor for a duration of %s\n", Settings.ExitAfter)
112+
emitter := goreplay.NewEmitter()
113+
go emitter.Start(plugins, goreplay.Settings.Middleware)
114+
if goreplay.Settings.ExitAfter > 0 {
115+
log.Printf("Running gor for a duration of %s\n", goreplay.Settings.ExitAfter)
115116

116-
time.AfterFunc(Settings.ExitAfter, func() {
117-
log.Printf("gor run timeout %s\n", Settings.ExitAfter)
117+
time.AfterFunc(goreplay.Settings.ExitAfter, func() {
118+
log.Printf("gor run timeout %s\n", goreplay.Settings.ExitAfter)
118119
close(closeCh)
119120
})
120121
}

elasticsearch.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
package main
1+
package goreplay
22

33
import (
44
"encoding/json"
5+
"github.com/buger/goreplay/proto"
56
"log"
67
"net/url"
78
"strings"
89
"time"
910

10-
"github.com/buger/goreplay/proto"
11-
1211
elastigo "github.com/mattbaird/elastigo/lib"
1312
)
1413

elasticsearch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"testing"

emitter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package main
1+
package goreplay
22

33
import (
44
"fmt"
5+
"github.com/buger/goreplay/internal/byteutils"
56
"hash/fnv"
67
"io"
78
"log"
89
"sync"
910

10-
"github.com/buger/goreplay/byteutils"
1111
"github.com/coocood/freecache"
1212
)
1313

emitter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"fmt"

examples/middleware/token_modifier.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import (
2424
"bytes"
2525
"encoding/hex"
2626
"fmt"
27-
"os"
28-
2927
"github.com/buger/goreplay/proto"
28+
"os"
3029
)
3130

3231
// requestID -> originalToken

gor_stat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"runtime"

http_modifier.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"
55
"encoding/base64"
6+
"github.com/buger/goreplay/proto"
67
"hash/fnv"
78
"strings"
8-
9-
"github.com/buger/goreplay/proto"
109
)
1110

1211
type HTTPModifier struct {

http_modifier_settings.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"errors"
@@ -24,9 +24,7 @@ type HTTPModifierConfig struct {
2424
Methods HTTPMethods `json:"http-allow-method"`
2525
}
2626

27-
//
2827
// Handling of --http-allow-header, --http-disallow-header options
29-
//
3028
type headerFilter struct {
3129
name []byte
3230
regexp *regexp.Regexp
@@ -56,9 +54,7 @@ func (h *HTTPHeaderFilters) Set(value string) error {
5654
return nil
5755
}
5856

59-
//
6057
// Handling of --http-basic-auth-filter option
61-
//
6258
type basicAuthFilter struct {
6359
regexp *regexp.Regexp
6460
}
@@ -82,9 +78,7 @@ func (h *HTTPHeaderBasicAuthFilters) Set(value string) error {
8278
return nil
8379
}
8480

85-
//
8681
// Handling of --http-allow-header-hash and --http-allow-param-hash options
87-
//
8882
type hashFilter struct {
8983
name []byte
9084
percent uint32
@@ -129,9 +123,7 @@ func (h *HTTPHashFilters) Set(value string) error {
129123
return nil
130124
}
131125

132-
//
133126
// Handling of --http-set-header option
134-
//
135127
type httpHeader struct {
136128
Name string
137129
Value string
@@ -160,9 +152,7 @@ func (h *HTTPHeaders) Set(value string) error {
160152
return nil
161153
}
162154

163-
//
164155
// Handling of --http-set-param option
165-
//
166156
type httpParam struct {
167157
Name []byte
168158
Value []byte
@@ -208,9 +198,7 @@ func (h *HTTPMethods) Set(value string) error {
208198
return nil
209199
}
210200

211-
//
212201
// Handling of --http-rewrite-url option
213-
//
214202
type urlRewrite struct {
215203
src *regexp.Regexp
216204
target []byte
@@ -237,9 +225,7 @@ func (r *URLRewriteMap) Set(value string) error {
237225
return nil
238226
}
239227

240-
//
241228
// Handling of --http-rewrite-header option
242-
//
243229
type headerRewrite struct {
244230
header []byte
245231
src *regexp.Regexp
@@ -275,9 +261,7 @@ func (r *HeaderRewriteMap) Set(value string) error {
275261
return nil
276262
}
277263

278-
//
279264
// Handling of --http-allow-url option
280-
//
281265
type urlRegexp struct {
282266
regexp *regexp.Regexp
283267
}

http_modifier_settings_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"testing"

http_modifier_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"
5-
"testing"
6-
75
"github.com/buger/goreplay/proto"
6+
"testing"
87
)
98

109
func TestHTTPModifierWithoutConfig(t *testing.T) {

http_prettifier.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"
55
"compress/gzip"
66
"fmt"
7+
"github.com/buger/goreplay/proto"
78
"io/ioutil"
89
"net/http/httputil"
910
"strconv"
10-
11-
"github.com/buger/goreplay/proto"
1211
)
1312

1413
func prettifyHTTP(p []byte) []byte {

http_prettifier_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"
55
"compress/gzip"
6+
"github.com/buger/goreplay/proto"
67
"strconv"
78
"testing"
8-
9-
"github.com/buger/goreplay/proto"
109
)
1110

1211
func TestHTTPPrettifierGzip(t *testing.T) {

input_dummy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"time"

input_file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bufio"

input_file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"

input_http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"log"

input_http_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"

input_kafka.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"encoding/json"

input_kafka_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"testing"

input_raw.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
package main
1+
package goreplay
22

33
import (
44
"context"
55
"fmt"
6+
"github.com/buger/goreplay/internal/capture"
7+
"github.com/buger/goreplay/internal/tcp"
8+
"github.com/buger/goreplay/proto"
69
"log"
710
"net"
811
"strconv"
912
"strings"
1013
"sync"
11-
12-
"github.com/buger/goreplay/capture"
13-
"github.com/buger/goreplay/proto"
14-
"github.com/buger/goreplay/tcp"
1514
)
1615

1716
// RAWInputConfig represents configuration that can be applied on raw input

input_raw_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bytes"
5+
"github.com/buger/goreplay/internal/capture"
6+
"github.com/buger/goreplay/internal/tcp"
7+
"github.com/buger/goreplay/proto"
58
"io/ioutil"
69
"net"
710
"net/http"
@@ -13,10 +16,6 @@ import (
1316
"sync/atomic"
1417
"testing"
1518
"time"
16-
17-
"github.com/buger/goreplay/capture"
18-
"github.com/buger/goreplay/proto"
19-
"github.com/buger/goreplay/tcp"
2019
)
2120

2221
const testRawExpire = time.Millisecond * 200

input_tcp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package goreplay
22

33
import (
44
"bufio"

0 commit comments

Comments
 (0)