log-manager/main.go

80 lines
1.7 KiB
Go
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// Package classification JNX Log Manager API Documentation.
//
// Schemes: https
// Host: jannex
// BasePath: /v1
// Version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package main
import (
"jannex/log-manager/modules/config"
"jannex/log-manager/modules/loghandler"
"jannex/log-manager/modules/rabbitmq"
"jannex/log-manager/modules/structs"
"jannex/log-manager/modules/utils"
"jannex/log-manager/routers/router"
"time"
"git.ex.umbach.dev/Alex/roese-utils/rsconfig"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func init() {
rsconfig.CreateEnvConfigFileIfNotExists(`DEBUG=false
HOST=127.0.0.1
PORT=50110
SSE_SERVER_ENABLED=true
LOG_FOLDER=./logs/
# this determines how long the logs should be keept on the server after they will be deleted
DAYS_TO_KEEP_LOGS=30`)
config.LoadConfig()
utils.ValidatorInit()
utils.CreateDirectoryIfNotExists(config.Cfg.LogFolder)
// checking for deletable logs on startup
loghandler.CheckForDeletableLogs()
// starting the background log deleter
go loghandler.StartBackgroundLogDeleter()
}
func main() {
app := fiber.New(fiber.Config{
BodyLimit: 100 * 1024 * 1024,
})
app.Use(cors.New(cors.Config{}))
if config.Cfg.Debug {
app.Use(logger.New(logger.Config{
Format: "${pid} ${locals:requestid} ${status} - ${latency} ${method} ${path}\n",
}))
}
router.SetupRoutes(app)
loghandler.AddLog(structs.LogBody{
Type: "logserver",
Logs: []string{time.Now().Format("02-01-2006 15:04:05") + " Log Server started"},
})
go rabbitmq.Init()
app.Listen(config.Cfg.Host + ":" + config.Cfg.Port)
}