Documentation
¶
Index ¶
- Variables
- func AllURLParams(ctx *fasthttp.RequestCtx) map[string]string
- func RegisterMethod(method string) error
- func URLParam(ctx *fasthttp.RequestCtx, key string) string
- type Actions
- type Context
- type Handler
- type Mux
- func (mx *Mux) AddEndpoint(method, pattern string, handler Handler) error
- func (mx *Mux) AddEndpointWithActions(method, pattern string, actions *Actions, handler Handler) error
- func (mx *Mux) Find(rctx *Context, method, path string) Handler
- func (mx *Mux) FindWithActions(rctx *Context, method, path string) (Handler, *Actions)
- func (mx *Mux) Routes() []Route
- type Route
- type RouteParams
- type Router
- type Routes
Constants ¶
This section is empty.
Variables ¶
var (
// RouteCtxKey is the context.Context key to store the request context.
RouteCtxKey = &contextKey{"RouteContext"}
)
Functions ¶
func AllURLParams ¶ added in v0.7.1
func AllURLParams(ctx *fasthttp.RequestCtx) map[string]string
AllURLParams returns the map of the url parameters from a fasthttp.Request object.
func RegisterMethod ¶ added in v0.7.1
RegisterMethod adds support for custom HTTP method handlers, available via Router#Method and Router#MethodFunc
Types ¶
type Context ¶ added in v0.7.1
type Context struct {
Routes Routes
// Routing path/method override used during the route search.
// See Mux#routeHTTP method.
RoutePath string
RouteMethod string
// URLParams are the stack of routeParams captured during the
// routing lifecycle across a stack of sub-routers.
URLParams RouteParams
// Routing pattern stack throughout the lifecycle of the request,
// across all connected routers. It is a record of all matching
// patterns across a stack of sub-routers.
RoutePatterns []string
// contains filtered or unexported fields
}
Context is the default routing context set on the root node of a request context to track route patterns, URL parameters and an optional routing path.
func NewRouteContext ¶ added in v0.7.1
func NewRouteContext() *Context
NewRouteContext returns a new routing Context object.
func RouteContext ¶ added in v0.7.1
func RouteContext(ctx *fasthttp.RequestCtx) *Context
RouteContext returns chi's routing Context object from a http.Request Context.
func (*Context) Reset ¶ added in v0.7.1
func (x *Context) Reset()
Reset a routing context to its initial state.
func (*Context) RoutePattern ¶ added in v0.7.1
RoutePattern builds the routing pattern string for the particular request, at the particular point during routing. This means, the value will change throughout the execution of a request in a router. That is why its advised to only use this value after calling the next handler.
For example,
func Instrument(next web.Handler) web.Handler {
return web.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
routePattern := chi.RouteContext(r.Context()).RoutePattern()
measure(w, r, routePattern)
})
}
type Handler ¶ added in v0.7.1
type Handler func(ctx *fasthttp.RequestCtx) error
A Handler is a type that handles an http request within our own little mini framework.
type Mux ¶ added in v0.7.1
type Mux struct {
// contains filtered or unexported fields
}
Mux is a simple fastHTTP route multiplexer that parses a request path, records any URL params, and searched for the appropriate web.Handler. It implements the web.Handler interface and is friendly with the standard library.
func NewMux ¶ added in v0.7.1
func NewMux() *Mux
NewMux returns a newly initialized Mux object that implements the Router interface.
func NewRouter ¶
func NewRouter() *Mux
NewRouter returns a new Mux object that implements the Router interface.
func (*Mux) AddEndpoint ¶ added in v0.7.1
AddEndpoint adds the route `pattern` that matches `method` http method to execute the `handler` web.Handler.
func (*Mux) AddEndpointWithActions ¶ added in v0.9.0
func (mx *Mux) AddEndpointWithActions(method, pattern string, actions *Actions, handler Handler) error
AddEndpointWithActions adds the route `pattern` that matches `method` http method to execute the `handler` web.Handler.
func (*Mux) FindWithActions ¶ added in v0.9.0
FindWithActions searches Handler by method + path and returns it + actions
type RouteParams ¶ added in v0.7.1
type RouteParams struct {
Keys, Values []string
}
RouteParams is a structure to track URL routing parameters efficiently.
func (*RouteParams) Add ¶ added in v0.7.1
func (s *RouteParams) Add(key, value string)
Add will append a URL parameter to the end of the route param
type Router ¶
type Router interface {
Routes
// AddEndpoint adds routes for `pattern` that matches
// the `method` HTTP method.
AddEndpoint(method, pattern string, handler Handler) error
}
Router consisting of the core routing methods used by chi's Mux, using only the standard net/http.
type Routes ¶ added in v0.7.1
type Routes interface {
// Find searches the routing tree for a handler that matches
// the method/path - similar to routing a http request, but without
// executing the handler thereafter.
Find(rctx *Context, method, path string) Handler
// FindWithActions searches the routing tree for a handler and actions that matches
// the method/path - similar to routing a http request, but without
// executing the handler thereafter.
FindWithActions(rctx *Context, method, path string) (Handler, *Actions)
}
Routes interface adds two methods for router traversal, which is also used by the `docgen` subpackage to generation documentation for Routers.