Documentation ¶
Index ¶
- func PathParam(req *http.Request, name string) (value string)
- func PathParams(req *http.Request) (params map[string]string)
- func RequestPath(req *http.Request) (value string)
- type Middleware
- type MiddlewareFunc
- type Route
- func (r *Route) Any(handler http.Handler) *Route
- func (r *Route) AnyFunc(f http.HandlerFunc) *Route
- func (r *Route) Connect(handler http.Handler) *Route
- func (r *Route) ConnectFunc(f http.HandlerFunc) *Route
- func (r *Route) Delete(handler http.Handler) *Route
- func (r *Route) DeleteFunc(f http.HandlerFunc) *Route
- func (r *Route) Get(handler http.Handler) *Route
- func (r *Route) GetFunc(f http.HandlerFunc) *Route
- func (r *Route) Head(handler http.Handler) *Route
- func (r *Route) HeadFunc(f http.HandlerFunc) *Route
- func (r *Route) Middleware(m Middleware) *Route
- func (r *Route) MiddlewareExceptFor(m Middleware, verbs ...string) *Route
- func (r *Route) MiddlewareExceptForOptions(m Middleware) *Route
- func (r *Route) MiddlewareFor(m Middleware, verbs ...string) *Route
- func (r *Route) MiddlewareFunc(m MiddlewareFunc) *Route
- func (r *Route) NotFound(handler http.Handler) *Route
- func (r *Route) NotFoundFunc(f http.HandlerFunc) *Route
- func (r *Route) Options(handler http.Handler) *Route
- func (r *Route) OptionsFunc(f http.HandlerFunc) *Route
- func (r *Route) Patch(handler http.Handler) *Route
- func (r *Route) PatchFunc(f http.HandlerFunc) *Route
- func (r *Route) Post(handler http.Handler) *Route
- func (r *Route) PostFunc(f http.HandlerFunc) *Route
- func (r *Route) Put(handler http.Handler) *Route
- func (r *Route) PutFunc(f http.HandlerFunc) *Route
- func (r *Route) Redirect(url string, permanent bool) *Route
- func (r *Route) Route(path string) *Route
- type ServeMux
- func (s *ServeMux) Handle(path string, handler http.Handler)
- func (s *ServeMux) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request))
- func (s *ServeMux) HandleHost(host, path string, handler http.Handler)
- func (s *ServeMux) Handler(r *http.Request) (http.Handler, string)
- func (s *ServeMux) HandlerAndMiddleware(r *http.Request) (http.Handler, []Middleware, string)
- func (s *ServeMux) Middleware(path string, middleware Middleware)
- func (s *ServeMux) MiddlewareExceptFor(path string, middleware Middleware, verbs ...string)
- func (s *ServeMux) MiddlewareFor(path string, middleware Middleware, verbs ...string)
- func (s *ServeMux) MiddlewareFunc(path string, m MiddlewareFunc) *Route
- func (s *ServeMux) MiddlewareHost(host, path string, middleware Middleware)
- func (s *ServeMux) NotFound(handler http.Handler)
- func (s *ServeMux) Route(path string) *Route
- func (s *ServeMux) RouteHost(host, path string) *Route
- func (s *ServeMux) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (s *ServeMux) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PathParam ¶
PathParam gets named path parameters and their values from the request
the path '/users/:name' given '/users/andrew' will have `PathParam(r, "name")` => `"andrew"` unset values return an empty stringRoutes
func PathParams ¶
PathParams returns the map of all path parameters and their values from the request.
Altering the values of this map will not affect future calls to PathParam and PathParams.
func RequestPath ¶
RequestPath returns the path definition that the router used to serve this request, without any parameter substitution.
Types ¶
type Middleware ¶
type Middleware interface {
ServeHTTPMiddleware(http.ResponseWriter, *http.Request, func(http.ResponseWriter, *http.Request))
}
Middleware handles HTTP requests and optionally passes them along to the next handler in the chain.
type MiddlewareFunc ¶
type MiddlewareFunc func(http.ResponseWriter, *http.Request, func(http.ResponseWriter, *http.Request))
The MiddlewareFunc type is an adapter to allow the use of ordinary functions as HTTP middlewares.
If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (MiddlewareFunc) ServeHTTPMiddleware ¶
func (m MiddlewareFunc) ServeHTTPMiddleware(rw http.ResponseWriter, req *http.Request, n func(http.ResponseWriter, *http.Request))
ServeHTTPMiddleware calls f(w, r, n).
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
A Route represents a specific path for a request. Routes can be absolute paths, rooted subtrees, or path parameters that accept any stringRoutes.
func (*Route) Any ¶
Any registers a catch-all handler for any method sent to this route. This takes lower precedence than a specific method match.
func (*Route) AnyFunc ¶
func (r *Route) AnyFunc(f http.HandlerFunc) *Route
AnyFunc registers a plain function as a catch-all handler for any method sent to this route. This takes lower precedence than a specific method match.
func (*Route) ConnectFunc ¶
func (r *Route) ConnectFunc(f http.HandlerFunc) *Route
ConnectFunc adds a plain function as a handler for CONNECT methods to this route.
func (*Route) DeleteFunc ¶
func (r *Route) DeleteFunc(f http.HandlerFunc) *Route
DeleteFunc adds a plain function as a handler for DELETE methods to this route.
func (*Route) Get ¶
Get adds a handler for GET methods to this route. GET handlers will also be called for HEAD requests if no specific HEAD handler is registered.
func (*Route) GetFunc ¶
func (r *Route) GetFunc(f http.HandlerFunc) *Route
GetFunc adds a plain function as a handler for GET methods to this route. GET handlers will also be called for HEAD requests if no specific HEAD handler is registered.
func (*Route) HeadFunc ¶
func (r *Route) HeadFunc(f http.HandlerFunc) *Route
HeadFunc adds a plain function as a handler for HEAD methods to this route.
func (*Route) Middleware ¶
func (r *Route) Middleware(m Middleware) *Route
Middleware adds a middleware to this Route.
Middlewares are executed if the path to the target route crosses this route.
func (*Route) MiddlewareExceptFor ¶ added in v1.1.0
func (r *Route) MiddlewareExceptFor(m Middleware, verbs ...string) *Route
MiddlewareExceptFor adds a middleware to this node, but will only be executed for requests that are not in the list of verbs. Verbs are case sensitive, and should use the `http.Method*` constants. Panics if any of the verbs provided are unknown.
func (*Route) MiddlewareExceptForOptions ¶ added in v1.1.0
func (r *Route) MiddlewareExceptForOptions(m Middleware) *Route
MiddlewareExceptForOptions is shorthand for MiddlewareExceptFor with http.MethodOptions as the only excepted method
func (*Route) MiddlewareFor ¶ added in v1.1.0
func (r *Route) MiddlewareFor(m Middleware, verbs ...string) *Route
MiddlewareFor adds a middleware to this node, but will only be executed for requests with the verb specified. Verbs are case sensitive, and should use the `http.Method*` constants. Panics if any of the verbs provided are unknown.
func (*Route) MiddlewareFunc ¶
func (r *Route) MiddlewareFunc(m MiddlewareFunc) *Route
MiddlewareFunc registers a plain function as a middleware.
func (*Route) NotFound ¶
NotFound adds a handler for requests that do not correspond to a route. This handler will also be called for any routes further down the path from this point if no other not found handlers are registered below.
func (*Route) NotFoundFunc ¶
func (r *Route) NotFoundFunc(f http.HandlerFunc) *Route
NotFoundFunc adds a plain function as a handler for requests that do not correspond to a route. This handler will also be called for any routes further down the path from this point if no other not found handlers are registered below.
func (*Route) Options ¶
Options adds a handler for OPTIONS methods to this route. This handler will also be called for any routes further down the path from this point if no other OPTIONS handlers are registered below.
func (*Route) OptionsFunc ¶
func (r *Route) OptionsFunc(f http.HandlerFunc) *Route
OptionsFunc adds a plain function as a handler for OPTIONS methods to this route. This handler will also be called for any routes further down the path from this point if no other OPTIONS handlers are registered below.
func (*Route) PatchFunc ¶
func (r *Route) PatchFunc(f http.HandlerFunc) *Route
PatchFunc adds a plain function as a handler for PATCH methods to this route.
func (*Route) PostFunc ¶
func (r *Route) PostFunc(f http.HandlerFunc) *Route
PostFunc adds a plain function as a handler for POST methods to this route.
func (*Route) PutFunc ¶
func (r *Route) PutFunc(f http.HandlerFunc) *Route
PutFunc adds a plain function as a handler for PUT methods to this route.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is the multiplexer for http requests
func NewServeMux ¶
func NewServeMux() *ServeMux
NewServeMux creates a new multiplexer, and sets up a default not found handler
func (*ServeMux) Handle ¶
Handle registers the handler for the given pattern. If a handler already exists for pattern it is overwritten.
func (*ServeMux) HandleFunc ¶
HandleFunc registers the handler function for the given pattern.
func (*ServeMux) HandleHost ¶
HandleHost registers the handler for the given pattern and host. If a handler already exists for pattern it is overwritten.
func (*ServeMux) Handler ¶
Handler returns the handler to use for the given request, consulting r.Method, r.Host, and r.URL.Path. It always returns a non-nil handler. If the path is not in its canonical form, the handler will be an internally-generated handler that redirects to the canonical path.
Handler also returns the registered pattern that matches the request or, in the case of internally-generated redirects, the pattern that will match after following the redirect.
If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.
func (*ServeMux) HandlerAndMiddleware ¶
HandlerAndMiddleware returns the same as Handler, but with the addition of an array of middleware, in the order they would have been executed
func (*ServeMux) Middleware ¶
func (s *ServeMux) Middleware(path string, middleware Middleware)
Middleware adds middleware for the given pattern.
func (*ServeMux) MiddlewareExceptFor ¶ added in v1.1.0
func (s *ServeMux) MiddlewareExceptFor(path string, middleware Middleware, verbs ...string)
MiddlewareExceptFor adds a middleware to this node, but will only be executed for requests that are not in the list of verbs. Verbs are case sensitive, and should use the `http.Method*` constants. Panics if any of the verbs provided are unknown.
func (*ServeMux) MiddlewareFor ¶ added in v1.1.0
func (s *ServeMux) MiddlewareFor(path string, middleware Middleware, verbs ...string)
MiddlewareFor adds a middleware to this node, but will only be executed for requests with the verb specified. Verbs are case sensitive, and should use the `http.Method*` constants. Panics if any of the verbs provided are unknown.
func (*ServeMux) MiddlewareFunc ¶
func (s *ServeMux) MiddlewareFunc(path string, m MiddlewareFunc) *Route
MiddlewareFunc registers a plain function as a middleware.
func (*ServeMux) MiddlewareHost ¶
func (s *ServeMux) MiddlewareHost(host, path string, middleware Middleware)
MiddlewareHost adds middleware for the given pattern.
func (*ServeMux) RouteHost ¶
RouteHost returns the route from the root of the domain to the given pattern on a specific domain