Documentation
¶
Overview ¶
Package routing provides a high-performance segment-tree HTTP router.
Index ¶
- type Group
- func (g *Group) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route
- func (g *Group) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Group(prefix string, fn func(*Group))
- func (g *Group) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (g *Group) Use(mw ...onihttp.MiddlewareFunc) *Group
- type Route
- type Router
- func (r *Router) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route
- func (r *Router) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Group(prefix string, fn func(*Group), mw ...onihttp.MiddlewareFunc)
- func (r *Router) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) NotFound(h onihttp.HandlerFunc)
- func (r *Router) OnError(h func(*onihttp.Context, error))
- func (r *Router) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
- func (r *Router) Routes() []*Route
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) URL(name string, params ...string) (string, error)
- func (r *Router) Use(mw ...onihttp.MiddlewareFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a route group with a shared prefix and middleware stack.
func (*Group) Any ¶
func (g *Group) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route
Any registers a route for all common HTTP methods.
func (*Group) Delete ¶
func (g *Group) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Delete registers a DELETE route on this group.
func (*Group) Get ¶
func (g *Group) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Get registers a GET route on this group.
func (*Group) Head ¶
func (g *Group) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Head registers a HEAD route on this group.
func (*Group) Options ¶
func (g *Group) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Options registers an OPTIONS route on this group.
func (*Group) Patch ¶
func (g *Group) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Patch registers a PATCH route on this group.
func (*Group) Post ¶
func (g *Group) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Post registers a POST route on this group.
func (*Group) Put ¶
func (g *Group) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
Put registers a PUT route on this group.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route is a handle to a registered route, used for post-registration configuration (naming, route-level middleware) and introspection.
func (*Route) Middleware ¶
func (r *Route) Middleware(mw ...onihttp.MiddlewareFunc) *Route
Middleware appends route-level middleware (runs after global middleware).
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is the OniWorks HTTP router. It matches incoming requests against a per-method segment tree and dispatches them through a precomposed middleware chain. Route matching is O(path depth), independent of the number of routes.
func (*Router) Any ¶
func (r *Router) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route
func (*Router) Delete ¶
func (r *Router) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) Get ¶
func (r *Router) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) Group ¶
func (r *Router) Group(prefix string, fn func(*Group), mw ...onihttp.MiddlewareFunc)
Group creates a route group with a shared prefix and optional middleware.
func (*Router) Head ¶
func (r *Router) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) NotFound ¶
func (r *Router) NotFound(h onihttp.HandlerFunc)
NotFound sets a custom handler for unmatched routes.
func (*Router) Options ¶
func (r *Router) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) Patch ¶
func (r *Router) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) Post ¶
func (r *Router) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) Put ¶
func (r *Router) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler so Router can be passed directly to http.Server.
func (*Router) URL ¶
URL generates a URL for a named route, substituting params.
r.URL("user.show", "id", "42") → "/users/42"
func (*Router) Use ¶
func (r *Router) Use(mw ...onihttp.MiddlewareFunc)
Use appends global middleware that runs before every route handler.