From fc3ee13f657df0d444c235eec97f047f1aed5836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 29 Oct 2020 22:12:33 +0100 Subject: [PATCH] move logger to http package. --- internal/http/http.go | 5 ++--- internal/http/{middleware => }/logger.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) rename internal/http/{middleware => }/logger.go (98%) diff --git a/internal/http/http.go b/internal/http/http.go index c0322c2f..0a9b15bd 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -12,7 +12,6 @@ import ( "github.com/rs/zerolog/log" "demodesk/neko/internal/http/endpoint" - customMiddleware "demodesk/neko/internal/http/middleware" "demodesk/neko/internal/types" "demodesk/neko/internal/types/config" ) @@ -30,7 +29,7 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server { router := chi.NewRouter() router.Use(middleware.Recoverer) // Recover from panics without crashing server router.Use(middleware.RequestID) // Create a request ID for each request - router.Use(customMiddleware.Logger) // Log API request calls using custom logger function + router.Use(Logger) // Log API request calls using custom logger function router.Get("/ws", func(w http.ResponseWriter, r *http.Request) { if webSocketHandler.Upgrade(w, r) != nil { @@ -51,7 +50,7 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server { router.NotFound(endpoint.Handle(func(w http.ResponseWriter, r *http.Request) error { return &endpoint.HandlerError{ Status: http.StatusNotFound, - Message: fmt.Sprintf("file '%s' is not found", r.RequestURI), + Message: fmt.Sprintf("Endpoint '%s' was not found.", r.RequestURI), } })) diff --git a/internal/http/middleware/logger.go b/internal/http/logger.go similarity index 98% rename from internal/http/middleware/logger.go rename to internal/http/logger.go index b20ea9ac..dabffea1 100644 --- a/internal/http/middleware/logger.go +++ b/internal/http/logger.go @@ -1,4 +1,4 @@ -package middleware +package http import ( "fmt"