Documentation
¶
Overview ¶
Package mux is a small, idomatic http router
Index ¶
- func Logger(next http.Handler) http.Handler
- type Middleware
- type Router
- func (router *Router) All(pattern string, handler http.HandlerFunc)
- func (router *Router) CustomMethod(method, pattern string, handle http.HandlerFunc)
- func (router *Router) Delete(pattern string, handler http.HandlerFunc)
- func (router *Router) Get(pattern string, handler http.HandlerFunc)
- func (router *Router) Group(prefix string, middlewares ...Middleware) *Router
- func (router *Router) NotAllowed(h func(http.ResponseWriter, string, int)) *Router
- func (router *Router) NotFound(h func(http.ResponseWriter, *http.Request)) *Router
- func (router *Router) Patch(pattern string, handler http.HandlerFunc)
- func (router *Router) Post(pattern string, handler http.HandlerFunc)
- func (router *Router) Put(pattern string, handler http.HandlerFunc)
- func (router *Router) Run(addr string)
- func (router *Router) ServeFile(pattern, file string)
- func (router *Router) ServeFileFS(pattern, file string, fs fs.FS)
- func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (router *Router) Static(pattern, dir string)
- func (router *Router) StaticFS(pattern string, fs fs.FS)
- func (router *Router) Use(middlewares ...Middleware)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Middleware ¶
Middleware defines a function that wraps an http.Handler.
type Router ¶
Router provides a chain of middlewares and routes.
func DefaultRouter ¶
func DefaultRouter() *Router
DefaultRouter creates a new Router using the default ServeMux.
func NewRouter ¶
func NewRouter(l *slog.Logger, middleware ...Middleware) *Router
NewRouter creates a new Router with the given middleware applied.
func (*Router) All ¶
func (router *Router) All(pattern string, handler http.HandlerFunc)
All registers the handler for all methods on given pattern.
func (*Router) CustomMethod ¶ added in v0.2.0
func (router *Router) CustomMethod(method, pattern string, handle http.HandlerFunc)
CustomMethod registers a handler for a custom method request.
func (*Router) Delete ¶
func (router *Router) Delete(pattern string, handler http.HandlerFunc)
Delete registers the handler for delete requests on given pattern.
func (*Router) Get ¶
func (router *Router) Get(pattern string, handler http.HandlerFunc)
Get registers the handler for get requests on given pattern.
func (*Router) Group ¶
func (router *Router) Group(prefix string, middlewares ...Middleware) *Router
Group creates a sub-router for the given prefix and applies middleware to it.
func (*Router) NotAllowed ¶ added in v0.2.0
NotAllowed sets a custom method not allowed error.
func (*Router) Patch ¶
func (router *Router) Patch(pattern string, handler http.HandlerFunc)
Patch registers the handler for patch requests on given pattern.
func (*Router) Post ¶
func (router *Router) Post(pattern string, handler http.HandlerFunc)
Post registers the handler for post requests on given pattern.
func (*Router) Put ¶
func (router *Router) Put(pattern string, handler http.HandlerFunc)
Put registers the handler for Put requests on given pattern.
func (*Router) ServeFileFS ¶ added in v0.2.1
ServeFileFS registers a ServeFileFS handler.
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
func (*Router) StaticFS ¶ added in v0.2.1
StaticFS registers the handle to serve static files from FS filesystem. ex. //go:embded images var content embed.FS router.StaticFS("/images/", content) .
func (*Router) Use ¶
func (router *Router) Use(middlewares ...Middleware)
Use adds a chain of middlewares to the router.