add logs
This commit is contained in:
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"acc-server-manager/local/service"
|
"acc-server-manager/local/service"
|
||||||
"acc-server-manager/local/utl/common"
|
"acc-server-manager/local/utl/common"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@@ -111,6 +112,7 @@ func (ac *ApiController) stopServer(c *fiber.Ctx) error {
|
|||||||
c.Locals("serverId", model.ServerId)
|
c.Locals("serverId", model.ServerId)
|
||||||
apiModel, err := ac.service.ApiStopServer(c)
|
apiModel, err := ac.service.ApiStopServer(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Print(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||||
}
|
}
|
||||||
return c.SendString(apiModel)
|
return c.SendString(apiModel)
|
||||||
@@ -133,6 +135,7 @@ func (ac *ApiController) restartServer(c *fiber.Ctx) error {
|
|||||||
c.Locals("serverId", model.ServerId)
|
c.Locals("serverId", model.ServerId)
|
||||||
apiModel, err := ac.service.ApiRestartServer(c)
|
apiModel, err := ac.service.ApiRestartServer(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Print(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||||
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
return c.Status(400).SendString(strings.ReplaceAll(err.Error(), "\x00", ""))
|
||||||
}
|
}
|
||||||
return c.SendString(apiModel)
|
return c.SendString(apiModel)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"acc-server-manager/local/service"
|
"acc-server-manager/local/service"
|
||||||
"acc-server-manager/local/utl/common"
|
"acc-server-manager/local/utl/common"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
@@ -50,6 +51,7 @@ func (ac *ConfigController) updateConfig(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
var config map[string]interface{}
|
var config map[string]interface{}
|
||||||
if err := c.BodyParser(&config); err != nil {
|
if err := c.BodyParser(&config); err != nil {
|
||||||
|
log.Print("Invalid config format")
|
||||||
return c.Status(400).JSON(fiber.Map{"error": "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 {
|
func (ac *ConfigController) getConfig(c *fiber.Ctx) error {
|
||||||
Model, err := ac.service.GetConfig(c)
|
Model, err := ac.service.GetConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Print(err.Error())
|
||||||
return c.Status(400).SendString(err.Error())
|
return c.Status(400).SendString(err.Error())
|
||||||
}
|
}
|
||||||
return c.JSON(Model)
|
return c.JSON(Model)
|
||||||
@@ -92,6 +95,7 @@ func (ac *ConfigController) getConfig(c *fiber.Ctx) error {
|
|||||||
func (ac *ConfigController) getConfigs(c *fiber.Ctx) error {
|
func (ac *ConfigController) getConfigs(c *fiber.Ctx) error {
|
||||||
Model, err := ac.service.GetConfigs(c)
|
Model, err := ac.service.GetConfigs(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Print(err.Error())
|
||||||
return c.Status(400).SendString(err.Error())
|
return c.Status(400).SendString(err.Error())
|
||||||
}
|
}
|
||||||
return c.JSON(Model)
|
return c.JSON(Model)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"acc-server-manager/local/service"
|
"acc-server-manager/local/service"
|
||||||
"acc-server-manager/local/utl/common"
|
"acc-server-manager/local/utl/common"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -22,22 +23,22 @@ func InitializeControllers(c *dig.Container) {
|
|||||||
|
|
||||||
err := c.Invoke(NewApiController)
|
err := c.Invoke(NewApiController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("unable to initialize api controller")
|
log.Panic("unable to initialize api controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Invoke(NewConfigController)
|
err = c.Invoke(NewConfigController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("unable to initialize config controller")
|
log.Panic("unable to initialize config controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Invoke(NewServerController)
|
err = c.Invoke(NewServerController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("unable to initialize server controller")
|
log.Panic("unable to initialize server controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Invoke(NewLookupController)
|
err = c.Invoke(NewLookupController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("unable to initialize lookup controller")
|
log.Panic("unable to initialize lookup controller")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@@ -166,6 +167,7 @@ func (as ConfigService) GetConfig(ctx *fiber.Ctx) (interface{}, error) {
|
|||||||
server := as.serverRepository.GetFirst(ctx.UserContext(), serverID)
|
server := as.serverRepository.GetFirst(ctx.UserContext(), serverID)
|
||||||
|
|
||||||
if server == nil {
|
if server == nil {
|
||||||
|
log.Print("Server not found")
|
||||||
return nil, fiber.NewError(404, "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)
|
server := as.serverRepository.GetFirst(ctx.UserContext(), serverID)
|
||||||
|
|
||||||
if server == nil {
|
if server == nil {
|
||||||
|
log.Print("Server not found")
|
||||||
return nil, fiber.NewError(404, "Server not found")
|
return nil, fiber.NewError(404, "Server not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"acc-server-manager/local/model"
|
"acc-server-manager/local/model"
|
||||||
"acc-server-manager/local/repository"
|
"acc-server-manager/local/repository"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
@@ -30,7 +31,10 @@ func (as ServerService) GetAll(ctx *fiber.Ctx) *[]model.Server {
|
|||||||
servers := as.repository.GetAll(ctx.UserContext())
|
servers := as.repository.GetAll(ctx.UserContext())
|
||||||
|
|
||||||
for i, server := range *servers {
|
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)
|
(*servers)[i].Status = model.ServiceStatus(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +50,10 @@ func (as ServerService) GetAll(ctx *fiber.Ctx) *[]model.Server {
|
|||||||
// string: Application version
|
// string: Application version
|
||||||
func (as ServerService) GetById(ctx *fiber.Ctx, serverID int) *model.Server {
|
func (as ServerService) GetById(ctx *fiber.Ctx, serverID int) *model.Server {
|
||||||
server := as.repository.GetFirst(ctx.UserContext(), serverID)
|
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)
|
server.Status = model.ServiceStatus(status)
|
||||||
|
|
||||||
return server
|
return server
|
||||||
|
|||||||
Reference in New Issue
Block a user