Documentation
¶
Index ¶
- Variables
- func MethodNotAllowedHandler(c *Context)
- func NotFoundHandler(c *Context)
- func Serialize(data interface{}) (bytes []byte, err error)
- type Context
- func (c *Context) Abort()
- func (c *Context) Engine() *Engine
- func (c *Context) Get(name string) (value interface{})
- func (c *Context) GetEx(name string) (value interface{}, ok bool)
- func (c *Context) HTML(status int, name string, obj interface{})
- func (c *Context) JSON(status int, obj interface{})
- func (c *Context) JSONP(status int, callbackName string, obj interface{})
- func (c *Context) Next()
- func (c *Context) Param(name string) string
- func (c *Context) Set(name string, value interface{})
- func (c *Context) String(status int, text string)
- func (c *Context) URL(route string, pairs ...interface{}) string
- func (c *Context) Unset(name string)
- func (c *Context) WriteData(data interface{}) (err error)
- func (c *Context) XML(status int, obj interface{})
- type Engine
- func (r *Engine) HandleRequest(ctx *fasthttp.RequestCtx)
- func (r *Engine) NotFound(handlers ...Handler)
- func (r *Engine) Route(name string) *Route
- func (r *Engine) Run(addr string) (err error)
- func (r *Engine) RunTLS(addr string, certFile, keyFile string) (err error)
- func (r *Engine) RunUnix(addr string, mode os.FileMode) (err error)
- func (r *Engine) Use(handlers ...Handler)
- type Handler
- type Route
- func (r *Route) CONNECT(handlers ...Handler) *Route
- func (r *Route) DELETE(handlers ...Handler) *Route
- func (r *Route) GET(handlers ...Handler) *Route
- func (r *Route) HEAD(handlers ...Handler) *Route
- func (r *Route) Name(name string) *Route
- func (r *Route) OPTIONS(handlers ...Handler) *Route
- func (r *Route) PATCH(handlers ...Handler) *Route
- func (r *Route) POST(handlers ...Handler) *Route
- func (r *Route) PUT(handlers ...Handler) *Route
- func (r *Route) TRACE(handlers ...Handler) *Route
- func (r *Route) To(methods string, handlers ...Handler) *Route
- func (r *Route) URL(pairs ...interface{}) (s string)
- type RouterGroup
- func (r *RouterGroup) Any(path string, handlers ...Handler) *Route
- func (r *RouterGroup) CONNECT(path string, handlers ...Handler) *Route
- func (r *RouterGroup) DELETE(path string, handlers ...Handler) *Route
- func (r *RouterGroup) GET(path string, handlers ...Handler) *Route
- func (r *RouterGroup) Group(path string, handlers ...Handler) *RouterGroup
- func (r *RouterGroup) HEAD(path string, handlers ...Handler) *Route
- func (r *RouterGroup) OPTIONS(path string, handlers ...Handler) *Route
- func (r *RouterGroup) PATCH(path string, handlers ...Handler) *Route
- func (r *RouterGroup) POST(path string, handlers ...Handler) *Route
- func (r *RouterGroup) PUT(path string, handlers ...Handler) *Route
- func (r *RouterGroup) Static(path, root string, compress ...bool) *Route
- func (r *RouterGroup) TRACE(path string, handlers ...Handler) *Route
- func (r *RouterGroup) To(methods, path string, handlers ...Handler) *Route
- func (r *RouterGroup) Use(handlers ...Handler)
- type SerializeFunc
Constants ¶
This section is empty.
Variables ¶
var Methods = []string{
"CONNECT",
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PATCH",
"POST",
"PUT",
"TRACE",
}
Methods lists all supported HTTP methods by Engine.
Functions ¶
func MethodNotAllowedHandler ¶
func MethodNotAllowedHandler(c *Context)
MethodNotAllowedHandler handles the situation when a request has matching route without matching HTTP method. In this case, the handler will respond with an Allow HTTP header listing the allowed HTTP methods. Otherwise, the handler will do nothing and let the next handler (usually a NotFoundHandler) to handle the problem.
func NotFoundHandler ¶
func NotFoundHandler(c *Context)
NotFoundHandler returns a 404 HTTP error indicating a request has no matching route.
Types ¶
type Context ¶
type Context struct {
*fasthttp.RequestCtx
Serialize SerializeFunc // the function serializing the given data of arbitrary type into a byte array.
// contains filtered or unexported fields
}
Context represents the contextual data and environment while processing an incoming HTTP request.
func (*Context) Abort ¶
func (c *Context) Abort()
Abort skips the rest of the handlers associated with the current route. Abort is normally used when a handler handles the request normally and wants to skip the rest of the handlers. If a handler wants to indicate an error condition, it should simply return the error without calling Abort.
func (*Context) Get ¶
Get returns the named data item previously registered with the context by calling Set. If the named data item cannot be found, nil will be returned.
func (*Context) Next ¶
func (c *Context) Next()
Next calls the rest of the handlers associated with the current route. If any of these handlers returns an error, Next will return the error and skip the following handlers. Next is normally used when a handler needs to do some postprocessing after the rest of the handlers are executed.
func (*Context) Param ¶
Param returns the named parameter value that is found in the URL path matching the current route. If the named parameter cannot be found, an empty string will be returned.
func (*Context) Set ¶
Set stores the named data item in the context so that it can be retrieved later.
func (*Context) URL ¶
URL creates a URL using the named route and the parameter values. The parameters should be given in the sequence of name1, value1, name2, value2, and so on. If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL. Parameter values will be properly URL encoded. The method returns an empty string if the URL creation fails.
type Engine ¶
type Engine struct {
RouterGroup
Render *render.Render
// contains filtered or unexported fields
}
Engine manages routes and dispatches HTTP requests to the handlers of the matching routes.
func (*Engine) HandleRequest ¶
func (r *Engine) HandleRequest(ctx *fasthttp.RequestCtx)
HandleRequest handles the HTTP request.
func (*Engine) NotFound ¶
NotFound specifies the handlers that should be invoked when the engine cannot find any route matching a request. Note that the handlers registered via Use will be invoked first in this case.
func (*Engine) Route ¶
Route returns the named route. Nil is returned if the named route cannot be found.
func (*Engine) Run ¶
Run attaches the engine to a fasthttp server and starts listening and serving HTTP requests. It is a shortcut for fasthttp.ListenAndServe(addr, engine.HandleRequest) Note: this method will block the calling goroutine indefinitely unless an error happens.
func (*Engine) RunTLS ¶
RunTLS attaches the engine to a fasthttp server and starts listening and serving HTTPS (secure) requests. It is a shortcut for fasthttp.ListenAndServeTLS(addr, certFile, keyFile, engine.HandleRequest) Note: this method will block the calling goroutine indefinitely unless an error happens.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents a URL path pattern that can be used to match requested URLs.
func (*Route) Name ¶
Name sets the name of the route. This method will update the registration of the route in the engine as well.
func (*Route) To ¶
To adds the route to the engine with the given HTTP methods and handlers. Multiple HTTP methods should be separated by commas (without any surrounding spaces).
func (*Route) URL ¶
URL creates a URL using the current route and the given parameters. The parameters should be given in the sequence of name1, value1, name2, value2, and so on. If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL. The method will perform URL encoding for all given parameter values.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup represents a group of routes that share the same path prefix.
func (*RouterGroup) Any ¶
func (r *RouterGroup) Any(path string, handlers ...Handler) *Route
Any adds a route with the given route, handlers, and the HTTP methods as listed in routing.Methods.
func (*RouterGroup) CONNECT ¶
func (r *RouterGroup) CONNECT(path string, handlers ...Handler) *Route
CONNECT adds a CONNECT route to the engine with the given route path and handlers.
func (*RouterGroup) DELETE ¶
func (r *RouterGroup) DELETE(path string, handlers ...Handler) *Route
DELETE adds a DELETE route to the engine with the given route path and handlers.
func (*RouterGroup) GET ¶
func (r *RouterGroup) GET(path string, handlers ...Handler) *Route
GET adds a GET route to the engine with the given route path and handlers.
func (*RouterGroup) Group ¶
func (r *RouterGroup) Group(path string, handlers ...Handler) *RouterGroup
Group creates a RouterGroup with the given route path and handlers. The new group will combine the existing path with the new one. If no handler is provided, the new group will inherit the handlers registered with the current group.
func (*RouterGroup) HEAD ¶
func (r *RouterGroup) HEAD(path string, handlers ...Handler) *Route
HEAD adds a HEAD route to the engine with the given route path and handlers.
func (*RouterGroup) OPTIONS ¶
func (r *RouterGroup) OPTIONS(path string, handlers ...Handler) *Route
OPTIONS adds an OPTIONS route to the engine with the given route path and handlers.
func (*RouterGroup) PATCH ¶
func (r *RouterGroup) PATCH(path string, handlers ...Handler) *Route
PATCH adds a PATCH route to the engine with the given route path and handlers.
func (*RouterGroup) POST ¶
func (r *RouterGroup) POST(path string, handlers ...Handler) *Route
POST adds a POST route to the engine with the given route path and handlers.
func (*RouterGroup) PUT ¶
func (r *RouterGroup) PUT(path string, handlers ...Handler) *Route
PUT adds a PUT route to the engine with the given route path and handlers.
func (*RouterGroup) Static ¶
func (r *RouterGroup) Static(path, root string, compress ...bool) *Route
Static serves files from the given file system root. Where: 'path' - relative path from current engine path on site (must be without trailing slash), 'root' - directory that contains served files. For example:
engine.Static("/static", "/var/www")
func (*RouterGroup) TRACE ¶
func (r *RouterGroup) TRACE(path string, handlers ...Handler) *Route
TRACE adds a TRACE route to the engine with the given route path and handlers.
func (*RouterGroup) To ¶
func (r *RouterGroup) To(methods, path string, handlers ...Handler) *Route
To adds a route to the engine with the given HTTP methods, route path, and handlers. Multiple HTTP methods should be separated by commas (without any surrounding spaces).
func (*RouterGroup) Use ¶
func (r *RouterGroup) Use(handlers ...Handler)
Use registers one or multiple handlers to the current route group. These handlers will be shared by all routes belong to this group and its subgroups.
type SerializeFunc ¶
SerializeFunc serializes the given data of arbitrary type into a byte array.
