Documentation ¶
Index ¶
- Constants
- Variables
- type Group
- func (g *Group) ANY(path string, handler gateway.ProxyHandler)
- func (g *Group) CONNECT(path string, handler gateway.ProxyHandler)
- func (g *Group) DELETE(path string, handler gateway.ProxyHandler)
- func (g *Group) GET(path string, handler gateway.ProxyHandler)
- func (g *Group) Group(path string) *Group
- func (g *Group) HEAD(path string, handler gateway.ProxyHandler)
- func (g *Group) Handle(method, path string, handler gateway.ProxyHandler)
- func (g *Group) OPTIONS(path string, handler gateway.ProxyHandler)
- func (g *Group) PATCH(path string, handler gateway.ProxyHandler)
- func (g *Group) POST(path string, handler gateway.ProxyHandler)
- func (g *Group) PUT(path string, handler gateway.ProxyHandler)
- func (g *Group) TRACE(path string, handler gateway.ProxyHandler)
- type Router
- func (r *Router) ANY(path string, handler gateway.ProxyHandler)
- func (r *Router) CONNECT(path string, handler gateway.ProxyHandler)
- func (r *Router) DELETE(path string, handler gateway.ProxyHandler)
- func (r *Router) GET(path string, handler gateway.ProxyHandler)
- func (r *Router) Group(path string) *Group
- func (r *Router) HEAD(path string, handler gateway.ProxyHandler)
- func (r *Router) Handle(method, path string, handler gateway.ProxyHandler)
- func (r *Router) Handler(ctx *fasthttp.RequestCtx, buf *pools.ByteBuffer)
- func (r *Router) List() map[string][]string
- func (r *Router) Lookup(ctx *fasthttp.RequestCtx) (gateway.ProxyHandler, bool)
- func (r *Router) Mutable(v bool)
- func (r *Router) OPTIONS(path string, handler gateway.ProxyHandler)
- func (r *Router) PATCH(path string, handler gateway.ProxyHandler)
- func (r *Router) POST(path string, handler gateway.ProxyHandler)
- func (r *Router) PUT(path string, handler gateway.ProxyHandler)
- func (r *Router) TRACE(path string, handler gateway.ProxyHandler)
Constants ¶
const MethodWild = "*"
MethodWild wild HTTP method
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a sub-router to group paths
func (*Group) ANY ¶
func (g *Group) ANY(path string, handler gateway.ProxyHandler)
ANY is a shortcut for group.Handle(router.MethodWild, path, handler)
WARNING: Use only for routes where the request method is not important
func (*Group) CONNECT ¶
func (g *Group) CONNECT(path string, handler gateway.ProxyHandler)
OPTIONS is a shortcut for group.Handle(fasthttp.MethodOptions, path, handler)
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, handler gateway.ProxyHandler)
DELETE is a shortcut for group.Handle(fasthttp.MethodDelete, path, handler)
func (*Group) GET ¶
func (g *Group) GET(path string, handler gateway.ProxyHandler)
GET is a shortcut for group.Handle(fasthttp.MethodGet, path, handler)
func (*Group) Group ¶
Group returns a new group. Path auto-correction, including trailing slashes, is enabled by default.
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, handler gateway.ProxyHandler)
HEAD is a shortcut for group.Handle(fasthttp.MethodHead, path, handler)
func (*Group) Handle ¶
func (g *Group) Handle(method, path string, handler gateway.ProxyHandler)
Handle registers a new request handler with the given path and method.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, handler gateway.ProxyHandler)
OPTIONS is a shortcut for group.Handle(fasthttp.MethodOptions, path, handler)
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, handler gateway.ProxyHandler)
PATCH is a shortcut for group.Handle(fasthttp.MethodPatch, path, handler)
func (*Group) POST ¶
func (g *Group) POST(path string, handler gateway.ProxyHandler)
POST is a shortcut for group.Handle(fasthttp.MethodPost, path, handler)
type Router ¶
type Router struct { // If enabled, adds the matched route path onto the ctx.UserValue context // before invoking the handler. // The matched route path is only added to handlers of routes that were // registered when this option was enabled. SaveMatchedRoutePath bool // Enables automatic redirection if the current route can't be matched but a // handler for the path with (without) the trailing slash exists. // For example if /foo/ is requested but a route only exists for /foo, the // client is redirected to /foo with http status code 301 for GET requests // and 308 for all other request methods. RedirectTrailingSlash bool // If enabled, the router tries to fix the current request path, if no // handle is registered for it. // First superfluous path elements like ../ or // are removed. // Afterwards the router does a case-insensitive lookup of the cleaned path. // If a handle can be found for this route, the router makes a redirection // to the corrected path with status code 301 for GET requests and 308 for // all other request methods. // For example /FOO and /..//Foo could be redirected to /foo. // RedirectTrailingSlash is independent of this option. RedirectFixedPath bool // If enabled, the router checks if another method is allowed for the // current route, if the current request can not be routed. // If this is the case, the request is answered with 'Method Not Allowed' // and HTTP status code 405. // If no other Method is allowed, the request is delegated to the NotFound // handler. HandleMethodNotAllowed bool // If enabled, the router automatically replies to OPTIONS requests. // Custom OPTIONS handlers take priority over automatic replies. HandleOPTIONS bool // An optional gateway.ProxyHandler that is called on automatic OPTIONS requests. // The handler is only called if HandleOPTIONS is true and no OPTIONS // handler for the specific path was set. // The "Allowed" header is set before calling the handler. GlobalOPTIONS gateway.ProxyHandler // Configurable gateway.ProxyHandler which is called when no matching route is // found. If it is not set, default NotFound is used. NotFound gateway.ProxyHandler // Configurable gateway.ProxyHandler which is called when a request // cannot be routed and HandleMethodNotAllowed is true. // If it is not set, ctx.Error with fasthttp.StatusMethodNotAllowed is used. // The "Allow" header with allowed request methods is set before the handler // is called. MethodNotAllowed gateway.ProxyHandler // Function to handle panics recovered from http handlers. // It should be used to generate a error page and return the http error code // 500 (Internal Server Error). // The handler can be used to keep your server from crashing because of // unrecovered panics. PanicHandler func(*fasthttp.RequestCtx, interface{}) // contains filtered or unexported fields }
Router is a gateway.ProxyHandler which can be used to dispatch requests to different handler functions via configurable routes
func New ¶
func New() *Router
New returns a new router. Path auto-correction, including trailing slashes, is enabled by default.
func (*Router) ANY ¶
func (r *Router) ANY(path string, handler gateway.ProxyHandler)
ANY is a shortcut for router.Handle(router.MethodWild, path, handler)
WARNING: Use only for routes where the request method is not important
func (*Router) CONNECT ¶
func (r *Router) CONNECT(path string, handler gateway.ProxyHandler)
CONNECT is a shortcut for router.Handle(fasthttp.MethodConnect, path, handler)
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handler gateway.ProxyHandler)
DELETE is a shortcut for router.Handle(fasthttp.MethodDelete, path, handler)
func (*Router) GET ¶
func (r *Router) GET(path string, handler gateway.ProxyHandler)
GET is a shortcut for router.Handle(fasthttp.MethodGet, path, handler)
func (*Router) Group ¶
Group returns a new group. Path auto-correction, including trailing slashes, is enabled by default.
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handler gateway.ProxyHandler)
HEAD is a shortcut for router.Handle(fasthttp.MethodHead, path, handler)
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handler gateway.ProxyHandler)
Handle registers a new request handler with the given path and method.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*Router) Handler ¶
func (r *Router) Handler(ctx *fasthttp.RequestCtx, buf *pools.ByteBuffer)
Handler makes the router implement the http.Handler interface.
func (*Router) Lookup ¶
func (r *Router) Lookup(ctx *fasthttp.RequestCtx) (gateway.ProxyHandler, bool)
Lookup allows the manual lookup of a method + path combo. This is e.g. useful to build a framework around this router. If the path was found, it returns the handler function and the path parameter values. Otherwise the third return value indicates whether a redirection to the same path with an extra / without the trailing slash should be performed.
func (*Router) Mutable ¶
Mutable allows updating the route handler
It's disabled by default ¶
WARNING: Use with care. It could generate unexpected behaviours
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handler gateway.ProxyHandler)
OPTIONS is a shortcut for router.Handle(fasthttp.MethodOptions, path, handler)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handler gateway.ProxyHandler)
PATCH is a shortcut for router.Handle(fasthttp.MethodPatch, path, handler)
func (*Router) POST ¶
func (r *Router) POST(path string, handler gateway.ProxyHandler)
POST is a shortcut for router.Handle(fasthttp.MethodPost, path, handler)