Documentation
¶
Index ¶
- Variables
- type Cors
- type Mux
- func (r *Mux) Connect(pattern string, handler http.HandlerFunc)
- func (r *Mux) Delete(pattern string, handler http.HandlerFunc)
- func (r *Mux) Find(rctx *chi.Context, method, path string) string
- func (r *Mux) Get(pattern string, handler http.HandlerFunc)
- func (r *Mux) GetScopes(path string) MuxRouteScope
- func (r *Mux) Group(fn func(r chi.Router)) chi.Router
- func (r *Mux) Handle(pattern string, handler http.Handler)
- func (r *Mux) HandleFunc(pattern string, handler http.HandlerFunc)
- func (r *Mux) Head(pattern string, handler http.HandlerFunc)
- func (r *Mux) Match(rctx *chi.Context, method string, path string) bool
- func (r *Mux) Method(method, pattern string, handler http.Handler)
- func (r *Mux) MethodFunc(method, pattern string, handler http.HandlerFunc)
- func (r *Mux) MethodNotAllowed(handlerFn http.HandlerFunc)
- func (r *Mux) Middlewares() chi.Middlewares
- func (r *Mux) Mount(pattern string, handler http.Handler)
- func (r *Mux) NotFound(handlerFn http.HandlerFunc)
- func (r *Mux) NotFoundHandler() http.HandlerFunc
- func (r *Mux) Options(pattern string, handler http.HandlerFunc)
- func (r *Mux) Patch(pattern string, handler http.HandlerFunc)
- func (r *Mux) Post(pattern string, handler http.HandlerFunc)
- func (r *Mux) Put(pattern string, handler http.HandlerFunc)
- func (r *Mux) Route(pattern string, fn func(r chi.Router)) chi.Router
- func (r *Mux) Routes() []chi.Route
- func (r *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Mux) Trace(pattern string, handler http.HandlerFunc)
- func (r *Mux) URLParam(rq *http.Request, key string) string
- func (r *Mux) Use(middlewares ...func(http.Handler) http.Handler)
- func (r *Mux) With(middlewares ...func(http.Handler) http.Handler) chi.Router
- type MuxRouteInfo
- type MuxRouteScope
Constants ¶
This section is empty.
Variables ¶
var MuxRouterTree []MuxRouteInfo
var Router = &Mux{}
Functions ¶
This section is empty.
Types ¶
type Cors ¶
type Cors struct {
AllowedOrigins []string `yaml:"AllowedOrigins"`
// AllowOriginFunc is a custom function to validate the origin. It takes the origin
// as argument and returns true if allowed or false otherwise. If this option is
// set, the content of AllowedOrigins is ignored.
AllowOriginFunc func(r *http.Request, origin string) bool `yaml:"AllowOriginFunc"`
// AllowedMethods is a list of methods the client is allowed to use with
// cross-domain requests. Default value is simple methods (HEAD, GET and POST).
AllowedMethods []string `yaml:"AllowedMethods"`
// AllowedHeaders is list of non simple headers the client is allowed to use with
// cross-domain requests.
// If the special "*" value is present in the list, all headers will be allowed.
// Default value is [] but "Origin" is always appended to the list.
AllowedHeaders []string `yaml:"AllowedHeaders"`
// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
// API specification
ExposedHeaders []string `yaml:"ExposedHeaders"`
// AllowCredentials indicates whether the request can include user credentials like
// cookies, HTTP authentication or client side SSL certificates.
AllowCredentials bool `yaml:"AllowCredentials"`
// MaxAge indicates how long (in seconds) the results of a preflight request
// can be cached
MaxAge int `yaml:"MaxAge"`
// OptionsPassthrough instructs preflight to let other potential next handlers to
// process the OPTIONS method. Turn this on if your application handles OPTIONS.
OptionsPassthrough bool `yaml:"OptionsPassthrough"`
// Debugging flag adds additional output to debug server side CORS issues
Debug bool `yaml:"Debug"`
}
type Mux ¶
func NewRouter ¶
func NewRouter() *Mux
Mux package is a wrapper designed to work with Chi. The purpose is two fold, expose all HTTP verbs that one will need to run a full server as well as setup a simple approach to introducing new methods on top of what the base package provides. We are drafting this package to help us introduce a cache to store the route and scope in memory and expose a method to check that a route's scopes during an HTTP request using a middleware. The usage is exactly the same as what we'd need to run a Chi router. But, we are going to call our wrapper to get things kicked off. For example, create a new router: a := NewRouter()
... now you are able to call any Chi method:
a.use()
func (*Mux) Connect ¶
func (r *Mux) Connect(pattern string, handler http.HandlerFunc)
Connect adds the route `pattern` that matches a CONNECT http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Delete ¶
func (r *Mux) Delete(pattern string, handler http.HandlerFunc)
Delete adds the route `pattern` that matches a DELETE http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Get ¶
func (r *Mux) Get(pattern string, handler http.HandlerFunc)
Get adds the route `pattern` that matches a GET http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) GetScopes ¶
func (r *Mux) GetScopes(path string) MuxRouteScope
Mux route tree traversal to locate a route and return the scopes attached to the pattern.
func (*Mux) Group ¶
Group creates a new inline-Mux with a copy of middleware stack. It's useful
for a group of handlers along the same routing path that use an additional
set of middlewares.
func (*Mux) Handle ¶
Handle adds the route `pattern` that matches any http method to execute the `handler` http.Handler.
func (*Mux) HandleFunc ¶
func (r *Mux) HandleFunc(pattern string, handler http.HandlerFunc)
HandleFunc adds the route `pattern` that matches any http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Head ¶
func (r *Mux) Head(pattern string, handler http.HandlerFunc)
Head adds the route `pattern` that matches a HEAD http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Match ¶
Match searches the routing tree for a handler that matches the method/path. It's similar to routing a http request, but without executing the handler thereafter. Note: the *Context state is updated during execution, so manage the state carefully or make a NewRouteContext().
func (*Mux) Method ¶
Method and MethodFunc adds routes for `pattern` that matches the `method` HTTP method.
func (*Mux) MethodFunc ¶
func (r *Mux) MethodFunc(method, pattern string, handler http.HandlerFunc)
Method and MethodFunc adds routes for `pattern` that matches the `method` HTTP method.
func (*Mux) MethodNotAllowed ¶
func (r *Mux) MethodNotAllowed(handlerFn http.HandlerFunc)
MethodNotAllowed sets a custom http.HandlerFunc for routing paths where the method is unresolved. The default handler returns a 405 with an empty body.
func (*Mux) Middlewares ¶
func (r *Mux) Middlewares() chi.Middlewares
Middlewares returns a slice of middleware handler functions.
func (*Mux) Mount ¶
Mount attaches another http.Handler or chi Router as a subrouter along a routing path. It's very useful to split up a large API as many independent routers and compose them as a single service using Mount.
func (*Mux) NotFound ¶
func (r *Mux) NotFound(handlerFn http.HandlerFunc)
NotFound sets a custom http.HandlerFunc for routing paths that could not
be found. The default 404 handler is `http.NotFound`.
func (*Mux) NotFoundHandler ¶
func (r *Mux) NotFoundHandler() http.HandlerFunc
NotFoundHandler returns the default Mux 404 responder whenever a route cannot be found.
func (*Mux) Options ¶
func (r *Mux) Options(pattern string, handler http.HandlerFunc)
Options adds the route `pattern` that matches an OPTIONS http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Patch ¶
func (r *Mux) Patch(pattern string, handler http.HandlerFunc)
Patch adds the route `pattern` that matches a PATCH http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Post ¶
func (r *Mux) Post(pattern string, handler http.HandlerFunc)
Post adds the route `pattern` that matches a POST http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Put ¶
func (r *Mux) Put(pattern string, handler http.HandlerFunc)
Put adds the route `pattern` that matches a PUT http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Route ¶
Route creates a new Mux and mounts it along the `pattern` as a subrouter. Effectively, this is a short-hand call to Mount.
func (*Mux) Routes ¶
Routes returns a slice of routing information from the tree, useful for traversing available routes of a router.
func (*Mux) ServeHTTP ¶
func (r *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP is the single method of the http.Handler interface that makes Mux interoperable with the standard library. It uses a sync.Pool to get and reuse routing contexts for each request.
func (*Mux) Trace ¶
func (r *Mux) Trace(pattern string, handler http.HandlerFunc)
Trace adds the route `pattern` that matches a TRACE http method to execute the `handlerFn` http.HandlerFunc.
func (*Mux) Use ¶
Use appends a middleware handler to the Mux middleware stack. The middleware stack for any Mux will execute before searching for a matching route to a specific handler, which provides opportunity to respond early, change the course of the request execution, or set request-scoped values for the next http.Handler.
type MuxRouteInfo ¶
type MuxRouteScope ¶
type MuxRouteScope struct {
Scope []string
}