- Fix GetPrefixDistribution to count unique prefixes using COUNT(DISTINCT prefix) instead of COUNT(*) - Add /prefixlength/<length> route showing random sample of 500 prefixes - Make prefix counts on status page clickable links to prefix length pages - Add GetRandomPrefixesByLength database method - Create prefix_length.html template with sortable table - Show prefix age and origin AS with descriptions
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
)
|
|
|
|
// setupRoutes configures the HTTP routes
|
|
func (s *Server) setupRoutes() {
|
|
r := chi.NewRouter()
|
|
|
|
// Middleware
|
|
r.Use(middleware.RequestID)
|
|
r.Use(middleware.RealIP)
|
|
r.Use(middleware.Logger)
|
|
r.Use(middleware.Recoverer)
|
|
const requestTimeout = 2 * time.Second
|
|
r.Use(TimeoutMiddleware(requestTimeout))
|
|
r.Use(JSONResponseMiddleware)
|
|
|
|
// Routes
|
|
r.Get("/", s.handleRoot())
|
|
r.Get("/status", s.handleStatusHTML())
|
|
r.Get("/status.json", s.handleStatusJSON())
|
|
|
|
// AS and prefix detail pages
|
|
r.Get("/as/{asn}", s.handleASDetail())
|
|
r.Get("/prefix/{prefix}", s.handlePrefixDetail())
|
|
r.Get("/prefixlength/{length}", s.handlePrefixLength())
|
|
r.Get("/ip/{ip}", s.handleIPRedirect())
|
|
|
|
// API routes
|
|
r.Route("/api/v1", func(r chi.Router) {
|
|
r.Get("/stats", s.handleStats())
|
|
r.Get("/ip/{ip}", s.handleIPLookup())
|
|
r.Get("/as/{asn}", s.handleASDetailJSON())
|
|
r.Get("/prefix/{prefix}", s.handlePrefixDetailJSON())
|
|
})
|
|
|
|
s.router = r
|
|
}
|