From 8c42b656874edad6d55c2c8c533feabb67233521 Mon Sep 17 00:00:00 2001 From: Dj Walker-Morgan Date: Tue, 8 Sep 2020 10:29:44 +0100 Subject: [PATCH] Merge github.com/PierreZ/goStatic/pull/34/ --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 58d4da0..48c7f2c 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ var ( setBasicAuth = flag.String("set-basic-auth", "", "Define the basic auth. Form must be user:password") defaultUsernameBasicAuth = flag.String("default-user-basic-auth", "gopher", "Define the user") sizeRandom = flag.Int("password-length", 16, "Size of the randomized password") + logRequest = flag.Bool("enable-logging", false, "Enable log request") username string password string @@ -65,6 +66,15 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) { return w.Writer.Write(b) } +func handleReq(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if *logRequest { + log.Println(r.Method, r.URL.Path) + } + h.ServeHTTP(w, r) + }) +} + func main() { flag.Parse() @@ -85,7 +95,7 @@ func main() { } } - handler := http.FileServer(fileSystem) + handler := handleReq(http.FileServer(fileSystem)) pathPrefix := "/" if len(*context) > 0 {