Files
bamort/backend/cmd/main.go
T

171 lines
5.5 KiB
Go
Raw Normal View History

2025-07-24 07:39:43 +02:00
package main
import (
"bamort/appsystem"
2025-07-24 07:39:43 +02:00
"bamort/character"
2025-08-10 20:19:30 +02:00
"bamort/config"
2025-07-24 07:39:43 +02:00
"bamort/database"
2025-12-28 14:48:59 +01:00
"bamort/equipment"
2025-07-24 07:39:43 +02:00
"bamort/gsmaster"
2026-02-27 12:00:40 +01:00
"bamort/importer"
"bamort/importero"
2025-08-10 20:19:30 +02:00
"bamort/logger"
2025-07-24 07:39:43 +02:00
"bamort/maintenance"
2025-12-20 18:32:48 +01:00
"bamort/pdfrender"
2025-07-24 07:39:43 +02:00
"bamort/router"
"bamort/transfero"
2025-12-29 08:37:02 +01:00
"bamort/user"
2025-07-24 07:39:43 +02:00
"github.com/gin-gonic/gin"
2026-02-27 12:00:41 +01:00
// Swagger documentation
_ "bamort/docs/swagger"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
2025-07-24 07:39:43 +02:00
)
2026-01-25 21:57:58 +01:00
// @title BaMoRT API
2026-02-27 12:00:41 +01:00
// @version 2.0
// @description BaMoRT (MOAM Replacement) - Role-playing Game Character Management System API
// @description
// @description This API provides comprehensive character management, import/export functionality,
// @description master data management, and PDF generation for tabletop role-playing games.
// @description
// @description ## Authentication
// @description Most endpoints require authentication via JWT token. Obtain a token by calling POST /login.
// @description Include the token in the Authorization header: `Authorization: Bearer <token>`
// @description
// @description ## Character Import/Export
// @description The API supports pluggable adapters for importing/exporting characters from various systems.
// @description Supported formats include MOAM VTT, Foundry VTT, and more via microservice adapters.
//
// @contact.name BaMoRT Support
// @contact.email bamort.support@trokan.de
//
// @license.name Custom License
// @license.url https://github.com/Bardioc26/bamort/blob/main/LICENSE
//
2025-07-24 07:39:43 +02:00
// @host localhost:8180
// @BasePath /
2026-02-27 12:00:41 +01:00
// @schemes http https
//
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and the JWT token
2025-07-24 07:39:43 +02:00
func main() {
// Verwende die globale Konfigurationsvariable (bereits in config.init() geladen)
cfg := config.Cfg
2025-08-10 20:19:30 +02:00
// Logger konfigurieren
logger.SetDebugMode(cfg.DebugMode)
if cfg.LogLevel == "DEBUG" {
logger.SetMinLogLevel(logger.DEBUG)
} else if cfg.LogLevel == "WARN" {
logger.SetMinLogLevel(logger.WARN)
} else if cfg.LogLevel == "ERROR" {
logger.SetMinLogLevel(logger.ERROR)
} else {
logger.SetMinLogLevel(logger.INFO)
}
2026-01-25 21:57:58 +01:00
logger.Info("BaMoRT Server wird gestartet...")
2025-08-10 20:19:30 +02:00
logger.Debug("Debug-Modus ist aktiviert")
logger.Info("Environment: %s", cfg.Environment)
logger.Info("testingDB Set: %s", cfg.DevTesting)
2025-08-10 20:19:30 +02:00
logger.Info("Server Port: %s", cfg.ServerPort)
// Gin-Modus basierend auf Environment setzen
if cfg.IsProduction() {
gin.SetMode(gin.ReleaseMode)
logger.Info("Gin läuft im Release-Modus")
} else {
gin.SetMode(gin.DebugMode)
logger.Debug("Gin läuft im Debug-Modus")
}
// Datenbank verbinden
logger.Debug("Verbinde mit Datenbank...")
2025-07-24 07:39:43 +02:00
database.ConnectDatabase()
2025-08-10 20:19:30 +02:00
logger.Info("Datenbankverbindung erfolgreich")
2025-07-24 07:39:43 +02:00
2026-02-27 12:00:40 +01:00
// Run database migrations
logger.Debug("Führe Datenbank-Migrationen aus...")
if err := database.MigrateStructure(); err != nil {
logger.Error("Fehler bei Datenbank-Migrationen: %s", err.Error())
}
if err := importer.MigrateStructure(database.DB); err != nil {
logger.Error("Fehler bei Importer-Migrationen: %s", err.Error())
} else {
logger.Info("Datenbank-Migrationen erfolgreich")
}
2026-01-14 18:52:29 +01:00
/*
// Populate initial misc lookup data
logger.Debug("Initialisiere Misc-Lookup-Daten...")
2026-01-14 21:13:25 +01:00
if err := gsmaster.PopulateMiscLookupData(); err != nil {
2026-01-14 18:52:29 +01:00
logger.Warn("Fehler beim Initialisieren der Misc-Lookup-Daten: %s", err.Error())
} else {
logger.Info("Misc-Lookup-Daten erfolgreich initialisiert")
}
*/
2025-12-27 08:27:34 +01:00
// Initialize PDF templates
logger.Debug("Initialisiere PDF-Templates...")
if err := pdfrender.InitializeTemplates("/app/default_templates", cfg.TemplatesDir); err != nil {
logger.Warn("Fehler beim Initialisieren der Templates: %s", err.Error())
} else {
logger.Info("PDF-Templates erfolgreich initialisiert")
}
2026-02-27 12:00:40 +01:00
// Initialize import/export adapter registry
logger.Debug("Initialisiere Adapter-Registry...")
adapterRegistry := importer.NewAdapterRegistry()
importer.InitializeRegistry(adapterRegistry)
// Register adapters from config (if any)
// TODO: Load adapters from environment variable IMPORT_ADAPTERS
// For now, registry is empty and adapters can be registered manually
// Start background health checker (runs every 30s)
adapterRegistry.StartBackgroundHealthChecker()
logger.Info("Adapter-Registry erfolgreich initialisiert und Health-Checker gestartet")
2025-07-24 07:39:43 +02:00
r := gin.Default()
router.SetupGin(r)
2025-08-10 20:19:30 +02:00
// Routes registrieren
logger.Debug("Registriere API-Routen...")
2025-07-24 07:39:43 +02:00
protected := router.BaseRouterGrp(r)
// Register your module routes
2025-12-29 08:37:02 +01:00
user.RegisterRoutes(protected)
2025-07-24 07:39:43 +02:00
gsmaster.RegisterRoutes(protected)
character.RegisterRoutes(protected)
2025-12-28 14:48:59 +01:00
equipment.RegisterRoutes(protected)
2025-07-24 07:39:43 +02:00
maintenance.RegisterRoutes(protected)
importero.RegisterRoutes(protected)
2026-02-27 12:00:40 +01:00
importer.RegisterRoutes(protected) // New pluggable import/export system
2025-12-20 18:32:48 +01:00
pdfrender.RegisterRoutes(protected)
transfero.RegisterRoutes(protected)
appsystem.RegisterRoutes(protected)
2025-12-21 09:15:08 +01:00
// Register public routes (no authentication)
pdfrender.RegisterPublicRoutes(r)
appsystem.RegisterPublicRoutes(r)
2025-12-21 09:15:08 +01:00
2026-02-27 12:00:41 +01:00
// Swagger documentation endpoint
serverAddress := cfg.GetServerAddress()
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
logger.Info("Swagger UI verfügbar unter: %s/swagger/index.html", serverAddress)
2025-08-10 20:19:30 +02:00
logger.Info("API-Routen erfolgreich registriert")
2025-07-24 07:39:43 +02:00
2025-08-10 20:19:30 +02:00
// Server starten
logger.Info("Server startet auf Adresse: %s", serverAddress)
if err := r.Run(serverAddress); err != nil {
logger.Error("Fehler beim Starten des Servers: %s", err.Error())
panic(err)
}
2025-07-24 07:39:43 +02:00
}