Documentation ¶
Index ¶
- Variables
- func AllURLParams(ctx *fasthttp.RequestCtx) map[string]string
- func RegisterMethod(method string) error
- func URLParam(ctx *fasthttp.RequestCtx, key string) string
- func Walk(r Routes, walkFn WalkFunc) error
- type Context
- type Handler
- type Mux
- type Route
- type RouteParams
- type Router
- type Routes
- type WalkFunc
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.
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 { // Routes returns the routing tree in an easily traversable structure. Routes() []Route // 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 }
Routes interface adds two methods for router traversal, which is also used by the `docgen` subpackage to generation documentation for Routers.