Files
GoMFT/internal/web/handlers.go
T
StarFleetCPTN 2221e6a29c feat: Implement log viewer and WebSocket logging
- Added a new log viewer component to display real-time logs.
- Integrated WebSocket support for broadcasting log entries to connected clients.
- Updated main application to initialize logging and handle log directory creation.
- Enhanced error handling for log loading and broadcasting.
- Introduced new routes for accessing the log viewer and WebSocket stream.
2025-04-10 20:11:34 -07:00

51 lines
1.6 KiB
Go

package web
import (
"path/filepath"
"github.com/gin-gonic/gin"
"github.com/starfleetcptn/gomft/internal/config"
"github.com/starfleetcptn/gomft/internal/db"
"github.com/starfleetcptn/gomft/internal/email"
"github.com/starfleetcptn/gomft/internal/scheduler"
"github.com/starfleetcptn/gomft/internal/web/handlers"
)
// Handler is a wrapper around the handlers package
type Handler struct {
handlers *handlers.Handlers
}
// Global handlers instance for access from other packages
var globalHandlersInstance *handlers.Handlers
// GetHandlersInstance returns the global handlers instance and a boolean indicating if it's initialized
func GetHandlersInstance() (*handlers.Handlers, bool) {
return globalHandlersInstance, globalHandlersInstance != nil
}
// NewHandler creates a new Handler instance that delegates to the handlers package
func NewHandler(database *db.DB, scheduler *scheduler.Scheduler, jwtSecret string, dbPath string, backupDir string, cfg *config.Config) (*Handler, error) {
// Create email service instance
emailService := email.NewService(cfg)
// Use logs directory from config
logsDir := filepath.Join(cfg.DataDir, "logs")
// Create handlers instance
handlersInstance := handlers.NewHandlers(database, scheduler, jwtSecret, dbPath, backupDir, logsDir, emailService)
// Store the handlers instance globally
globalHandlersInstance = handlersInstance
return &Handler{
handlers: handlersInstance,
}, nil
}
// InitializeRoutes delegates route registration to the handlers package
func (h *Handler) InitializeRoutes(router *gin.Engine) {
// Register all routes through the handlers package
h.handlers.RegisterRoutes(router)
}