mirror of
https://github.com/buger/goreplay.git
synced 2026-10-19 16:15:42 +00:00
Add logging to the file-server
This commit is contained in:
@@ -6,6 +6,7 @@ TEST = TestRawListenerBench
|
||||
VERSION = DEV-$(shell date +%s)
|
||||
LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -extldflags \"-static\""
|
||||
MAC_LDFLAGS = -ldflags "-X main.VERSION=$(VERSION)"
|
||||
FADDR = ":8000"
|
||||
|
||||
release: release-x64 release-mac
|
||||
|
||||
@@ -68,7 +69,7 @@ run-3:
|
||||
sudo -E go run $(SOURCE) --input-tcp :27001 --output-stdout
|
||||
|
||||
file-server:
|
||||
go run $(SOURCE) file-server :8000
|
||||
go run $(SOURCE) file-server $(FADDR)
|
||||
|
||||
record:
|
||||
$(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -23,6 +24,14 @@ var (
|
||||
memprofile = flag.String("memprofile", "", "write memory profile to this file")
|
||||
)
|
||||
|
||||
func loggingMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
rb, _ := httputil.DumpRequest(r, false)
|
||||
log.Println(string(rb))
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
// // Don't exit on panic
|
||||
// defer func() {
|
||||
@@ -45,7 +54,7 @@ func main() {
|
||||
|
||||
log.Println("Started example file server for current dirrectory on address ", args[1])
|
||||
|
||||
log.Fatal(http.ListenAndServe(args[1], http.FileServer(http.Dir(dir))))
|
||||
log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(http.FileServer(http.Dir(dir)))))
|
||||
} else {
|
||||
flag.Parse()
|
||||
InitPlugins()
|
||||
|
||||
Reference in New Issue
Block a user