diff --git a/gotenberg.go b/gotenberg.go index 353a7cba..e6af6136 100644 --- a/gotenberg.go +++ b/gotenberg.go @@ -52,7 +52,7 @@ func main() { WriteTimeout: time.Second * 15, ReadTimeout: time.Second * 15, IdleTimeout: time.Second * 60, - Handler: middlewares.LoggingHandler(r), + Handler: r, } // runs our server in a goroutine so that it doesn't block. diff --git a/middlewares/middlewares.go b/middlewares/middlewares.go index ded24bbb..69e3cad8 100644 --- a/middlewares/middlewares.go +++ b/middlewares/middlewares.go @@ -20,20 +20,20 @@ import ( "github.com/satori/go.uuid" ) -// LoggingHandler identifies the request. -func LoggingHandler(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - transactionID := uuid.NewV4().String() - r = r.WithContext(context.WithTransactionID(r.Context(), transactionID)) - logger.InfoR(context.GetTransactionID(r.Context()), fmt.Sprintf("Handling new request from %s", r.RemoteAddr)) - next.ServeHTTP(w, r) - }) -} - // GetMiddlewaresChain builds and returns the chaining of handlers // using the alice library. func GetMiddlewaresChain() http.Handler { - return alice.New(enforceContentLengthHandler, enforceContentTypeHandler, convertHandler, serveHandler).ThenFunc(clearHandler) + return alice.New(loggingHandler, enforceContentLengthHandler, enforceContentTypeHandler, convertHandler, serveHandler).ThenFunc(clearHandler) +} + +// loggingHandler identifies the request. +func loggingHandler(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + transactionID := uuid.NewV4().String() + r = r.WithContext(context.WithTransactionID(r.Context(), transactionID)) + logger.InfoR(context.GetTransactionID(r.Context()), fmt.Sprintf("Hello %s", r.RemoteAddr)) + next.ServeHTTP(w, r) + }) } // enforeContentLengthHandler checks if the request has content. @@ -137,5 +137,5 @@ func clearHandler(w http.ResponseWriter, r *http.Request) { if err := c.Clear(); err != nil { logger.WarnR(context.GetTransactionID(r.Context()), err.Error()) } - logger.InfoR(context.GetTransactionID(r.Context()), "Request handled") + logger.InfoR(context.GetTransactionID(r.Context()), fmt.Sprintf("Bye %s", r.RemoteAddr)) }