From a22ab15a02d10e3994cdfe4cff528bb637971760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Jurmanovi=C4=87?= Date: Tue, 6 May 2025 23:59:01 +0200 Subject: [PATCH] add logs --- local/controller/api.go | 3 +++ local/controller/config.go | 4 ++++ local/controller/controller.go | 9 +++++---- local/service/config.go | 3 +++ local/service/server.go | 11 +++++++++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/local/controller/api.go b/local/controller/api.go index 03444fe..2e41464 100644 --- a/local/controller/api.go +++ b/local/controller/api.go @@ -3,6 +3,7 @@ package controller import ( "acc-server-manager/local/service" "acc-server-manager/local/utl/common" + "log" "strings" "github.com/gofiber/fiber/v2" @@ -111,6 +112,7 @@ func (ac *ApiController) stopServer(c *fiber.Ctx) error { c.Locals("serverId", model.ServerId) apiModel, err := ac.service.ApiStopServer(c) if err != nil { + log.Print(strings.ReplaceAll(err.Error(), "\x00", "")) return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", "")) } return c.SendString(apiModel) @@ -133,6 +135,7 @@ func (ac *ApiController) restartServer(c *fiber.Ctx) error { c.Locals("serverId", model.ServerId) apiModel, err := ac.service.ApiRestartServer(c) if err != nil { + log.Print(strings.ReplaceAll(err.Error(), "\x00", "")) return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", "")) } return c.SendString(apiModel) diff --git a/local/controller/config.go b/local/controller/config.go index 3dbc4bc..fb2bf34 100644 --- a/local/controller/config.go +++ b/local/controller/config.go @@ -3,6 +3,7 @@ package controller import ( "acc-server-manager/local/service" "acc-server-manager/local/utl/common" + "log" "github.com/gofiber/fiber/v2" ) @@ -50,6 +51,7 @@ func (ac *ConfigController) updateConfig(c *fiber.Ctx) error { var config map[string]interface{} if err := c.BodyParser(&config); err != nil { + log.Print("Invalid config format") return c.Status(400).JSON(fiber.Map{"error": "Invalid config format"}) } @@ -76,6 +78,7 @@ func (ac *ConfigController) updateConfig(c *fiber.Ctx) error { func (ac *ConfigController) getConfig(c *fiber.Ctx) error { Model, err := ac.service.GetConfig(c) if err != nil { + log.Print(err.Error()) return c.Status(400).SendString(err.Error()) } return c.JSON(Model) @@ -92,6 +95,7 @@ func (ac *ConfigController) getConfig(c *fiber.Ctx) error { func (ac *ConfigController) getConfigs(c *fiber.Ctx) error { Model, err := ac.service.GetConfigs(c) if err != nil { + log.Print(err.Error()) return c.Status(400).SendString(err.Error()) } return c.JSON(Model) diff --git a/local/controller/controller.go b/local/controller/controller.go index 1871830..f31109c 100644 --- a/local/controller/controller.go +++ b/local/controller/controller.go @@ -5,6 +5,7 @@ import ( "acc-server-manager/local/service" "acc-server-manager/local/utl/common" "fmt" + "log" "strconv" "strings" @@ -22,22 +23,22 @@ func InitializeControllers(c *dig.Container) { err := c.Invoke(NewApiController) if err != nil { - panic("unable to initialize api controller") + log.Panic("unable to initialize api controller") } err = c.Invoke(NewConfigController) if err != nil { - panic("unable to initialize config controller") + log.Panic("unable to initialize config controller") } err = c.Invoke(NewServerController) if err != nil { - panic("unable to initialize server controller") + log.Panic("unable to initialize server controller") } err = c.Invoke(NewLookupController) if err != nil { - panic("unable to initialize lookup controller") + log.Panic("unable to initialize lookup controller") } } diff --git a/local/service/config.go b/local/service/config.go index 5078975..b6f73c0 100644 --- a/local/service/config.go +++ b/local/service/config.go @@ -8,6 +8,7 @@ import ( "encoding/json" "errors" "io" + "log" "os" "path/filepath" "time" @@ -166,6 +167,7 @@ func (as ConfigService) GetConfig(ctx *fiber.Ctx) (interface{}, error) { server := as.serverRepository.GetFirst(ctx.UserContext(), serverID) if server == nil { + log.Print("Server not found") return nil, fiber.NewError(404, "Server not found") } @@ -190,6 +192,7 @@ func (as ConfigService) GetConfigs(ctx *fiber.Ctx) (*model.Configurations, error server := as.serverRepository.GetFirst(ctx.UserContext(), serverID) if server == nil { + log.Print("Server not found") return nil, fiber.NewError(404, "Server not found") } diff --git a/local/service/server.go b/local/service/server.go index 5fa2abb..650705c 100644 --- a/local/service/server.go +++ b/local/service/server.go @@ -3,6 +3,7 @@ package service import ( "acc-server-manager/local/model" "acc-server-manager/local/repository" + "log" "github.com/gofiber/fiber/v2" ) @@ -30,7 +31,10 @@ func (as ServerService) GetAll(ctx *fiber.Ctx) *[]model.Server { servers := as.repository.GetAll(ctx.UserContext()) for i, server := range *servers { - status, _ := as.apiService.StatusServer(server.ServiceName) + status, err := as.apiService.StatusServer(server.ServiceName) + if err != nil { + log.Print(err.Error()) + } (*servers)[i].Status = model.ServiceStatus(status) } @@ -46,7 +50,10 @@ func (as ServerService) GetAll(ctx *fiber.Ctx) *[]model.Server { // string: Application version func (as ServerService) GetById(ctx *fiber.Ctx, serverID int) *model.Server { server := as.repository.GetFirst(ctx.UserContext(), serverID) - status, _ := as.apiService.StatusServer(server.ServiceName) + status, err := as.apiService.StatusServer(server.ServiceName) + if err != nil { + log.Print(err.Error()) + } server.Status = model.ServiceStatus(status) return server