Documentation
¶
Index ¶
- func MuxRoutePattern(r *http.Request) string
- func Param(r *http.Request, name string) string
- func Params(r *http.Request) map[string]string
- type Router
- func (r *Router) Delete(pattern string, h http.Handler) error
- func (r *Router) Get(pattern string, h http.Handler) error
- func (r *Router) Group(prefix string, fn func(sub *Router))
- func (r *Router) Handle(method, pattern string, h http.Handler) error
- func (r *Router) HandleFunc(method, pattern string, hf func(http.ResponseWriter, *http.Request)) error
- func (r *Router) HandleFuncMethods(methods []string, pattern string, hf func(http.ResponseWriter, *http.Request)) error
- func (r *Router) HandleMethods(methods []string, pattern string, h http.Handler) error
- func (r *Router) MethodNotAllowed(h http.Handler)
- func (r *Router) NotFound(h http.Handler)
- func (r *Router) Patch(pattern string, h http.Handler) error
- func (r *Router) Post(pattern string, h http.Handler) error
- func (r *Router) Put(pattern string, h http.Handler) error
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(mw ...func(http.Handler) http.Handler)
- func (r *Router) UsePrefix(prefix string, mw ...func(http.Handler) http.Handler)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MuxRoutePattern ¶
MuxRoutePattern returns the matched route pattern from the request's context.
Types ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a lightweight HTTP router with named params, explicit wildcard, subrouter groups, and per-router middleware. It's intentionally small and dependency-free so it can be published later as a standalone module.
func (*Router) Group ¶
Group creates a subrouter with the provided prefix. The subrouter inherits middleware from the parent. Registration inside fn will register routes on the parent router but with the group's prefix applied.
func (*Router) Handle ¶
Handle registers a handler for the given method and pattern. Pattern syntax: segments separated by '/'. Named param: {name}. Wildcard: {*name} (must be last).
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(method, pattern string, hf func(http.ResponseWriter, *http.Request)) error
HandleFunc convenience wrapper.
func (*Router) HandleFuncMethods ¶
func (r *Router) HandleFuncMethods(methods []string, pattern string, hf func(http.ResponseWriter, *http.Request)) error
HandleFuncMethods convenience wrapper for HandleMethods.
func (*Router) HandleMethods ¶
HandleMethods registers the same handler for multiple HTTP methods.
func (*Router) MethodNotAllowed ¶
MethodNotAllowed sets a custom 405 handler.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler.
func (*Router) Use ¶
Use appends middleware to this router. Middleware will be applied in the order they are provided when wrapping handlers at registration time.
func (*Router) UsePrefix ¶
UsePrefix registers middleware that applies to all routes whose registered pattern matches the provided prefix by path segments. The prefix is normalized and matched in a segment-aware manner. UsePrefix applies the middleware to existing routes immediately and to future registrations.