From ad52dca10f1ef3aa0747f27695dbaf9706b7d7e0 Mon Sep 17 00:00:00 2001 From: Melora Hugues Date: Mon, 24 Jul 2023 23:05:50 +0200 Subject: [PATCH] Fix logs and services --- bootserver/controllers/client/client.go | 4 ++-- bootserver/controllers/client/enroll.go | 4 ++-- bootserver/middlewares/logger.go | 2 +- bootserver/server/server.go | 7 ++++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bootserver/controllers/client/client.go b/bootserver/controllers/client/client.go index 26a0780..350eef9 100644 --- a/bootserver/controllers/client/client.go +++ b/bootserver/controllers/client/client.go @@ -19,9 +19,9 @@ type BootController struct { l *logrus.Logger } -func NewBootController(logger *logrus.Logger) *BootController { +func NewBootController(logger *logrus.Logger, service *services.ClientHandlerService) *BootController { return &BootController{ - clientService: services.NewClientHandlerService(), + clientService: service, l: logger, } } diff --git a/bootserver/controllers/client/enroll.go b/bootserver/controllers/client/enroll.go index a68ab1f..aad8939 100644 --- a/bootserver/controllers/client/enroll.go +++ b/bootserver/controllers/client/enroll.go @@ -20,9 +20,9 @@ type EnrollController struct { l *logrus.Logger } -func NewEnrollController(l *logrus.Logger) *EnrollController { +func NewEnrollController(l *logrus.Logger, service *services.ClientHandlerService) *EnrollController { return &EnrollController{ - clientService: services.NewClientHandlerService(), + clientService: service, l: l, } } diff --git a/bootserver/middlewares/logger.go b/bootserver/middlewares/logger.go index df74f18..3acbba1 100644 --- a/bootserver/middlewares/logger.go +++ b/bootserver/middlewares/logger.go @@ -35,5 +35,5 @@ func (lm *LoggerMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) { clientIP = "unknown" } - lm.l.Infof(`%s - [%v] "%s %s %s" %d %d`, clientIP, currentTime, method, route, httpVersion, responseInfo.ReturnCode, responseInfo.ContentLength) + lm.l.Infof(`%s - [%s] "%s %s %s" %d %d`, clientIP, currentTime.Format(time.RFC3339), method, route, httpVersion, responseInfo.ReturnCode, responseInfo.ContentLength) } diff --git a/bootserver/server/server.go b/bootserver/server/server.go index 852ef68..f50a35a 100644 --- a/bootserver/server/server.go +++ b/bootserver/server/server.go @@ -12,6 +12,7 @@ import ( "git.faercol.me/faercol/http-boot-server/bootserver/config" "git.faercol.me/faercol/http-boot-server/bootserver/controllers/client" "git.faercol.me/faercol/http-boot-server/bootserver/middlewares" + "git.faercol.me/faercol/http-boot-server/bootserver/services" "github.com/sirupsen/logrus" ) @@ -63,10 +64,10 @@ func New(appConf *config.AppConfig, logger *logrus.Logger) (*Server, error) { default: panic(fmt.Errorf("unexpected listening mode %v", appConf.ServerMode)) } - + service := services.NewClientHandlerService() controllers := map[string]http.Handler{ - client.BootRoute: middlewares.WithLogger(client.NewBootController(logger), logger), - client.EnrollRoute: middlewares.WithLogger(client.NewEnrollController(logger), logger), + client.BootRoute: middlewares.WithLogger(client.NewBootController(logger, service), logger), + client.EnrollRoute: middlewares.WithLogger(client.NewEnrollController(logger, service), logger), } m := http.NewServeMux()