Documentation
¶
Index ¶
- func Chain(handler http.Handler, middlewares ...Middleware) http.Handler
- func ChainFunc(handler http.HandlerFunc, middlewares ...Middleware) http.Handler
- func PathParam(r *http.Request, key string) string
- func PrintRoutes(w io.Writer, stats RouteStats, format string, filters RouteFilters)
- func QueryParam(r *http.Request, key string) string
- func QueryParamDefault(r *http.Request, key, defaultValue string) string
- type ChiOption
- type Middleware
- type RouteFilters
- type RouteInfo
- type RouteStats
- type Router
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(handler http.Handler, middlewares ...Middleware) http.Handler
Chain applies middlewares to a handler. The first middleware in the list will be the outermost (executed first).
func ChainFunc ¶
func ChainFunc(handler http.HandlerFunc, middlewares ...Middleware) http.Handler
ChainFunc is like Chain but accepts http.HandlerFunc.
func PathParam ¶
PathParam extracts a URL path parameter from the request. This abstracts the underlying router implementation. Handlers should use this instead of directly calling chi.URLParam or r.PathValue.
func PrintRoutes ¶
func PrintRoutes(w io.Writer, stats RouteStats, format string, filters RouteFilters)
PrintRoutes prints routes to the given writer in the specified format.
func QueryParam ¶
QueryParam extracts a URL query parameter from the request.
Types ¶
type ChiOption ¶
type ChiOption func(*chiRouter)
ChiOption is a function that configures the Chi router.
func WithChiMiddleware ¶
func WithChiMiddleware() ChiOption
WithChiMiddleware adds Chi's built-in middleware.
type Middleware ¶
Middleware is a function that wraps an http.Handler. This follows the standard net/http middleware pattern.
type RouteFilters ¶
RouteFilters contains filter options for route listing.
type RouteStats ¶
RouteStats holds route statistics.
func CollectRoutes ¶
func CollectRoutes(router Router) RouteStats
CollectRoutes walks the router and collects all registered routes.
type Router ¶
type Router interface {
// HTTP method handlers with optional route-specific middleware.
// Middleware is applied in order: first middleware wraps outermost.
//
// Example:
// r.GET("/", handler) // No middleware
// r.GET("/", handler, authMiddleware) // With auth
// r.GET("/", handler, authMiddleware, loggingMiddleware) // Multiple
GET(path string, handler http.HandlerFunc, middlewares ...Middleware)
POST(path string, handler http.HandlerFunc, middlewares ...Middleware)
PUT(path string, handler http.HandlerFunc, middlewares ...Middleware)
PATCH(path string, handler http.HandlerFunc, middlewares ...Middleware)
DELETE(path string, handler http.HandlerFunc, middlewares ...Middleware)
// Group creates a new route group with prefix and optional middleware.
// Group middleware applies to all routes within the group.
Group(prefix string, fn func(Router), middlewares ...Middleware)
// Use adds middleware to the router (applies to all subsequent routes)
Use(middlewares ...Middleware)
// With returns a new Router with the given middleware applied.
// Prefer using inline middleware in route methods instead.
With(middlewares ...Middleware) Router
// Handler returns the http.Handler for use with http.Server
Handler() http.Handler
// Walk iterates over all registered routes.
// The callback receives method, path, and handler for each route.
Walk(fn func(method, path string, handler http.Handler) error) error
}
Router defines the interface for HTTP routing. This abstraction allows swapping the underlying router implementation (Chi, stdlib, Gin, etc.) without changing application code.
func NewChiRouter ¶
func NewChiRouter() Router
NewChiRouter creates a new Router using Chi as the underlying implementation.
func NewChiRouterWithOptions ¶
NewChiRouterWithOptions creates a router with custom options.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the HTTP server.
func NewServer ¶
NewServer creates a new HTTP server. By default, it uses Chi router. Use WithRouter option to change.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is a function that configures the server.
func WithRouter ¶
func WithRouter(r Router) ServerOption
WithRouter sets a custom router implementation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package handler provides HTTP handlers for the API server.
|
Package handler provides HTTP handlers for the API server. |
|
Package middleware provides HTTP middleware for the API server.
|
Package middleware provides HTTP middleware for the API server. |
|
Package routes registers all HTTP routes for the API.
|
Package routes registers all HTTP routes for the API. |