router

package
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

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
}

func (*Group) ANY added in v0.4.0

func (g *Group) ANY(path string, handler fasthttp.RequestHandler)

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 added in v0.4.0

func (g *Group) CONNECT(path string, handler fasthttp.RequestHandler)

OPTIONS is a shortcut for group.Handle(fasthttp.MethodOptions, path, handler)

func (*Group) DELETE added in v0.4.0

func (g *Group) DELETE(path string, handler fasthttp.RequestHandler)

DELETE is a shortcut for group.Handle(fasthttp.MethodDelete, path, handler)

func (*Group) GET added in v0.4.0

func (g *Group) GET(path string, handler fasthttp.RequestHandler)

GET is a shortcut for group.Handle(fasthttp.MethodGet, path, handler)

func (*Group) Group added in v0.4.0

func (g *Group) Group(path string) *Group

Group returns a new group. Path auto-correction, including trailing slashes, is enabled by default.

func (*Group) HEAD added in v0.4.0

func (g *Group) HEAD(path string, handler fasthttp.RequestHandler)

HEAD is a shortcut for group.Handle(fasthttp.MethodHead, path, handler)

func (*Group) Handle added in v0.4.0

func (g *Group) Handle(method, path string, handler fasthttp.RequestHandler)

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 added in v0.4.0

func (g *Group) OPTIONS(path string, handler fasthttp.RequestHandler)

OPTIONS is a shortcut for group.Handle(fasthttp.MethodOptions, path, handler)

func (*Group) PATCH added in v0.4.0

func (g *Group) PATCH(path string, handler fasthttp.RequestHandler)

PATCH is a shortcut for group.Handle(fasthttp.MethodPatch, path, handler)

func (*Group) POST added in v0.4.0

func (g *Group) POST(path string, handler fasthttp.RequestHandler)

POST is a shortcut for group.Handle(fasthttp.MethodPost, path, handler)

func (*Group) PUT added in v0.4.0

func (g *Group) PUT(path string, handler fasthttp.RequestHandler)

PUT is a shortcut for group.Handle(fasthttp.MethodPut, path, handler)

func (*Group) ServeFiles added in v0.4.0

func (g *Group) ServeFiles(path string, rootPath string)

ServeFiles serves files from the given file system root. The path must end with "/{filepath:*}", files are then served from the local path /defined/root/dir/{filepath:*}. For example if root is "/etc" and {filepath:*} is "passwd", the local file "/etc/passwd" would be served. Internally a fasthttp.FSHandler is used, therefore http.NotFound is used instead Use:

router.ServeFiles("/src/{filepath:*}", "./")

func (*Group) ServeFilesCustom added in v0.4.0

func (g *Group) ServeFilesCustom(path string, fs *fasthttp.FS)

ServeFilesCustom serves files from the given file system settings. The path must end with "/{filepath:*}", files are then served from the local path /defined/root/dir/{filepath:*}. For example if root is "/etc" and {filepath:*} is "passwd", the local file "/etc/passwd" would be served. Internally a fasthttp.FSHandler is used, therefore http.NotFound is used instead of the Router's NotFound handler. Use:

router.ServeFilesCustom("/src/{filepath:*}", *customFS)

func (*Group) TRACE added in v0.4.0

func (g *Group) TRACE(path string, handler fasthttp.RequestHandler)

OPTIONS is a shortcut for group.Handle(fasthttp.MethodOptions, path, handler)

type Router

type Router struct {
	// contains filtered or unexported fields
}

func New

func New() *Router

func (*Router) ANY

func (r *Router) ANY(path string, handler types.RequestHandler)

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 types.RequestHandler)

CONNECT is a shortcut for router.Handle(fasthttp.MethodConnect, path, handler)

func (*Router) DELETE

func (r *Router) DELETE(path string, handler types.RequestHandler)

DELETE is a shortcut for router.Handle(fasthttp.MethodDelete, path, handler)

func (*Router) Dispatch added in v0.4.0

func (r *Router) Dispatch(dispatch func(handler types.RequestHandler) fasthttp.RequestHandler)

func (*Router) GET

func (r *Router) GET(path string, handler types.RequestHandler)

GET is a shortcut for router.Handle(fasthttp.MethodGet, path, handler)

func (*Router) Group

func (r *Router) Group(path string) *Group

func (*Router) HEAD

func (r *Router) HEAD(path string, handler types.RequestHandler)

HEAD is a shortcut for router.Handle(fasthttp.MethodHead, path, handler)

func (*Router) Handle

func (r *Router) Handle(method, path string, handler types.RequestHandler)

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)

Handler makes the router implement the http.Handler interface.

func (*Router) List

func (r *Router) List() map[string][]string

func (*Router) Lookup

func (r *Router) Lookup(method, path string, ctx *fasthttp.RequestCtx) (fasthttp.RequestHandler, 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. Otherwise the second return value indicates whether a redirection to the same path with an extra / without the trailing slash should be performed.

func (*Router) Mutable

func (r *Router) Mutable(v bool)

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handler types.RequestHandler)

OPTIONS is a shortcut for router.Handle(fasthttp.MethodOptions, path, handler)

func (*Router) PATCH

func (r *Router) PATCH(path string, handler types.RequestHandler)

PATCH is a shortcut for router.Handle(fasthttp.MethodPatch, path, handler)

func (*Router) POST

func (r *Router) POST(path string, handler types.RequestHandler)

POST is a shortcut for router.Handle(fasthttp.MethodPost, path, handler)

func (*Router) PUT

func (r *Router) PUT(path string, handler types.RequestHandler)

PUT is a shortcut for router.Handle(fasthttp.MethodPut, path, handler)

func (*Router) ServeFiles

func (r *Router) ServeFiles(path string, rootPath string)

ServeFiles serves files from the given file system root. The path must end with "/{filepath:*}", files are then served from the local path /defined/root/dir/{filepath:*}. For example if root is "/etc" and {filepath:*} is "passwd", the local file "/etc/passwd" would be served. Internally a fasthttp.FSHandler is used, therefore fasthttp.NotFound is used instead Use:

router.ServeFiles("/src/{filepath:*}", "./")

func (*Router) ServeFilesCustom

func (r *Router) ServeFilesCustom(path string, fs *fasthttp.FS)

ServeFilesCustom serves files from the given file system settings. The path must end with "/{filepath:*}", files are then served from the local path /defined/root/dir/{filepath:*}. For example if root is "/etc" and {filepath:*} is "passwd", the local file "/etc/passwd" would be served. Internally a fasthttp.FSHandler is used, therefore http.NotFound is used instead of the Router's NotFound handler. Use:

router.ServeFilesCustom("/src/{filepath:*}", *customFS)

func (*Router) TRACE

func (r *Router) TRACE(path string, handler types.RequestHandler)

TRACE is a shortcut for router.Handle(fasthttp.MethodTrace, path, handler)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL