Major refactoring milestone - migrate all routes from main.go to internal/router/ package: ## Changes ### cmd/server/main.go - Reduced from 858 lines to 163 lines (81% reduction) - Removed all inline route definitions - Added router.RegisterRoutes() call with full config - Clean separation: setup → router registration → server start ### internal/router/ package Created comprehensive route organization: - router.go: Main router setup and JWT middleware - auth.go: Authentication routes (login, register, profile, etc.) - library.go: Library management routes - device.go: Device registration and management - sync.go: KOReader/Kobo sync + book matching + WebSocket - media.go: Media download, shelves, bulk operations - conflicts.go: Conflict resolution routes - analytics.go: Analytics API routes - queue.go: Sync queue management - opds.go: OPDS feed routes - frontend.go: SSR pages (/login, /admin, /dashboard, etc.) - docs.go: Documentation routes - helpers.go: Template rendering helpers ## Verification ✅ All 26 guideline checks pass ✅ Code compiles successfully ✅ Zero API behavior changes (100% compatible) ✅ Follows Go standard project layout ## Breaking Changes None - API compatibility fully maintained
24 lines
608 B
Go
24 lines
608 B
Go
package router
|
|
|
|
import (
|
|
"github.com/labstack/echo-jwt/v4"
|
|
)
|
|
|
|
func registerAnalyticsRoutes(cfg *Config) {
|
|
e := cfg.Echo
|
|
|
|
// JWT middleware for protected routes
|
|
jwtMiddleware := echojwt.WithConfig(echojwt.Config{
|
|
SigningKey: []byte(cfg.Cfg.JWTSecret),
|
|
ContextKey: "user",
|
|
})
|
|
|
|
protected := e.Group("/api", jwtMiddleware)
|
|
|
|
// Analytics routes
|
|
analytics := protected.Group("/analytics")
|
|
analytics.GET("/reading-stats", cfg.AnalyticsHandler.GetReadingStats)
|
|
analytics.GET("/device-usage", cfg.AnalyticsHandler.GetDeviceUsage)
|
|
analytics.GET("/popular-books", cfg.AnalyticsHandler.GetPopularBooks)
|
|
}
|