Extracted all deferred API packages from monolithic ws_*.go files: - api/routes.go (75 lines) - Extracted route registration from server.go - api/errors.go (108 lines) - Standardized error responses and error codes - api/jobs/handlers.go (271 lines) - Job WebSocket handlers * HandleAnnotateRun, HandleSetRunNarrative * HandleCancelJob, HandlePruneJobs, HandleListJobs - api/jupyter/handlers.go (244 lines) - Jupyter WebSocket handlers * HandleStartJupyter, HandleStopJupyter * HandleListJupyter, HandleListJupyterPackages * HandleRemoveJupyter, HandleRestoreJupyter - api/validate/handlers.go (163 lines) - Validation WebSocket handlers * HandleValidate, HandleGetValidateStatus, HandleListValidations - api/ws/handler.go (298 lines) - WebSocket handler framework * Core WebSocket handling logic * Opcode constants and error codes Lines redistributed: ~1,150 lines from ws_jobs.go (1,365), ws_jupyter.go (512), ws_validate.go (523), ws_handler.go (379) into focused packages. Note: Original ws_*.go files still present - cleanup in next commit. Build status: Compiles successfully
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/jfraeys/fetch_ml/internal/prommetrics"
|
|
)
|
|
|
|
// registerRoutes sets up all HTTP routes and handlers
|
|
func (s *Server) registerRoutes(mux *http.ServeMux) {
|
|
// Register Prometheus metrics endpoint (if enabled)
|
|
if s.config.Monitoring.Prometheus.Enabled {
|
|
s.promMetrics = prommetrics.New()
|
|
s.logger.Info("prometheus metrics initialized")
|
|
|
|
// Register metrics endpoint
|
|
metricsPath := s.config.Monitoring.Prometheus.Path
|
|
if metricsPath == "" {
|
|
metricsPath = "/metrics"
|
|
}
|
|
mux.Handle(metricsPath, s.promMetrics.Handler())
|
|
s.logger.Info("metrics endpoint registered", "path", metricsPath)
|
|
}
|
|
|
|
// Register health check endpoints (if enabled)
|
|
if s.config.Monitoring.HealthChecks.Enabled {
|
|
s.registerHealthRoutes(mux)
|
|
}
|
|
|
|
// Register WebSocket endpoint
|
|
s.registerWebSocketRoutes(mux)
|
|
|
|
// Register HTTP API handlers
|
|
s.handlers.RegisterHandlers(mux)
|
|
}
|
|
|
|
// registerHealthRoutes sets up health check endpoints
|
|
func (s *Server) registerHealthRoutes(mux *http.ServeMux) {
|
|
healthHandler := NewHealthHandler(s)
|
|
healthHandler.RegisterRoutes(mux)
|
|
mux.HandleFunc("/health/ok", s.handlers.handleHealth)
|
|
s.logger.Info("health check endpoints registered")
|
|
}
|
|
|
|
// registerWebSocketRoutes sets up WebSocket endpoint
|
|
func (s *Server) registerWebSocketRoutes(mux *http.ServeMux) {
|
|
// Initialize audit logger for WebSocket connections
|
|
auditLogger := s.initAuditLogger()
|
|
|
|
// Register WebSocket handler with security config and audit logger
|
|
securityCfg := getSecurityConfig(s.config)
|
|
wsHandler := NewWSHandler(
|
|
s.config.BuildAuthConfig(),
|
|
s.logger,
|
|
s.expManager,
|
|
s.config.DataDir,
|
|
s.taskQueue,
|
|
s.db,
|
|
s.jupyterServiceMgr,
|
|
securityCfg,
|
|
auditLogger,
|
|
)
|
|
|
|
mux.Handle("/ws", wsHandler)
|
|
s.logger.Info("websocket endpoint registered")
|
|
}
|