Skip to content

Commit 4094683

Browse files
authoredJan 12, 2023
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 14 additions & 13 deletions
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
}

0 commit comments

Comments
 (0)
Please sign in to comment.