About
NLG HTTP Router
router is a production-oriented HTTP routing package for Go focused on performance, composability, and clean application structure.
It combines radix-tree based route matching with middleware pipelines, hierarchical route grouping, request-scoped context utilities, recovery handling, rate limiting, profiling support, static asset serving, and multi-server orchestration in a lightweight API built on top of Go’s standard net/http interfaces.
Features
- Zero-Allocation Route Matching: Static, wildcard, parameterized, and mounted route lookups run with
0 B/opand0 allocs/opin benchmarks. - Fast Radix Router: Optimized radix-tree based route lookup for static, wildcard, and parameterized routes.
- Prepared Pattern Matching: Built-in prepared matchers for common route constraints such as UUIDs, digits, slugs, dates, hex values, base64 values, and safe path segments.
- Regex Route Parameters: Define custom route parameters with regular expressions and validation.
- Route Groups: Organize routes using hierarchical groups with inherited middleware.
- Middleware Pipeline: Compose global, grouped, and route-level middleware.
- Mount Support: Mount existing
http.Handlerandhttp.HandlerFuncimplementations under route prefixes. - Pooled Request Context: Per-request context with parameter access and temporary key/value storage backed by
sync.Pool. - Health check Endpoints: Built-in liveness and readiness route helpers.
- Rate Limiting Guard: Built-in middleware for request throttling and cooldown-based protection.
- Built-in pprof Profiling: Enable a dedicated profiling server with Go’s standard
net/http/pprof. - Static File Serving: Serve static directories with automatic
favicon.icosupport. - Custom NotFound Handler: Override the default
404 page not foundresponse. - Custom Recovery Handler: Recover from panics and provide your own fallback response.
- Panic Logging: Panic details are logged through Go’s standard
log/slog, including request method and path. - Access Logging: Optional middleware for structured request logging.
- Multi-Server Support: Run multiple listeners from a single router, useful for services exposing multiple ports.
- Graceful Shutdown: Handles interrupt and termination signals with safe HTTP server shutdown.
- Efficient Method Matching: Uses HTTP method bitmasks for fast method validation and
405 Method Not Allowedhandling. - Standard Library Compatible: Works with
net/http,http.Handler,http.HandlerFunc, andlog/slog.
Requirements
This package requires Go 1.25 or newer.
It is designed for modern Go projects and may use language and standard library features introduced in recent Go versions.
- Go:
1.25or newer - Dependencies: Standard library +
github.com/netlifeguru/logger - Features used: Generics, concurrency primitives
The package is optimized for concurrent workloads and low allocation overhead, making it suitable for APIs, internal services, edge gateways, backend platforms, and modern distributed systems.