Documentation
¶
Overview ¶
Package router provides pluggable HTTP routing with path parameter support.
This package defines a flexible routing interface that supports both exact matches and path parameters. It includes a built-in implementation with colon-style path parameters and can be extended with custom routing logic.
Route Mutation: The builtin router is not thread-safe for concurrent route mutations. Register or unregister routes during startup, or guard runtime changes with your own synchronization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuiltinRouter ¶
type BuiltinRouter struct {
// contains filtered or unexported fields
}
BuiltinRouter supports exact and param (colon/braces) patterns. Matching is deterministic: exact first, then param routes in registration order.
func NewBuiltinRouter ¶
func NewBuiltinRouter() *BuiltinRouter
NewBuiltinRouter creates a new BuiltinRouter.
Returns:
- *BuiltinRouter: A new BuiltinRouter instance.
func (*BuiltinRouter) Match ¶
func (r *BuiltinRouter) Match(req *http.Request) *Matched
Match matches a request to a route.
Parameters:
- req: The request to match.
Returns:
- *Matched: A Matched instance if the request matches a route.
func (*BuiltinRouter) MethodsFor ¶
func (r *BuiltinRouter) MethodsFor(path string) []string
MethodsFor returns the set of allowed methods for a given path. Provided for BuiltinRouter; adapters can implement the same method.
func (*BuiltinRouter) Register ¶
func (r *BuiltinRouter) Register( method, pattern string, h http.Handler, ) error
Register registers a new route.
Parameters:
- method: The HTTP method of the route.
- pattern: The pattern of the route.
- h: The handler of the route.
Returns:
- error: An error if the route registration fails.
func (*BuiltinRouter) Unregister ¶
func (r *BuiltinRouter) Unregister(method, pattern string) error
Unregister unregisters a route.
Parameters:
- method: The HTTP method of the route.
- pattern: The pattern of the route.
Returns:
- error: An error if the route unregistration fails.