fasthttp

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 14 Imported by: 1

README

fasthttp for Mojito

PRs Welcome

fasthttp for Mojito provides a fasthttp Router implementation that was designed specifically for Mojito with full compatibility.

SonarCloud Report


Quickstart

To start using fasthttp as your router just enable it as the default router like this:

func init() {
    fasthttp.AsDefault()
}

Or to use fasthttp as a secondary router you can register it as a named router like this:

func init() {
    fasthttp.As("myRouter")
}

Documentation

Read our Documentation, check out the Project Website.

Icon made with Gopherize and flaticon.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(name string)

As registers this router under a given name

func AsDefault

func AsDefault()

AsDefault registers this router as the default router

Types

type Response

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

func NewResponse

func NewResponse(ctx *fasthttp.RequestCtx) *Response

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*Response) Write

func (r *Response) Write(body []byte) (int, error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(status int)

type Router

type Router struct {
	Middleware []interface{}
	Routes     structures.Table[string, string, router.Handler]
	*fhttp.Server
	*fhttpRouter.Router

	ErrorHandler router.Handler
}

Router is a router implementation based on fasthttp

func NewRouter

func NewRouter() *Router

NewRouter will create new instance of the mojito fasthttp router implementation

func (*Router) CONNECT

func (r *Router) CONNECT(path string, handler interface{}) error

CONNECT will add a route to this router for the connect method

func (*Router) DELETE

func (r *Router) DELETE(path string, handler interface{}) error

DELETE will add a route to this router for the delete method

func (*Router) GET

func (r *Router) GET(path string, handler interface{}) error

GET will add a route to this router for the get method

func (*Router) HEAD

func (r *Router) HEAD(path string, handler interface{}) error

HEAD will add a route to this router for the head method

func (*Router) ListenAndServe

func (r *Router) ListenAndServe(address string) error

ListenAndServe will start an HTTP webserver on the given address

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handler interface{}) error

OPTIONS will add a route to this router for the options method

func (*Router) PATCH

func (r *Router) PATCH(path string, handler interface{}) error

PATCH will add a route to this router for the patch method

func (*Router) POST

func (r *Router) POST(path string, handler interface{}) error

POST will add a route to this router for the post method

func (*Router) PUT

func (r *Router) PUT(path string, handler interface{}) error

PUT will add a route to this router for the put method

func (*Router) Shutdown

func (r *Router) Shutdown() error

Shutdown will gracefully shutdown the router

func (*Router) TRACE

func (r *Router) TRACE(path string, handler interface{}) error

TRACE will add a route to this router for the trace method

func (*Router) WithErrorHandler

func (r *Router) WithErrorHandler(handler interface{}) error

WithErrorHandler will set the error handler for the router

func (*Router) WithGroup

func (r *Router) WithGroup(path string, callback func(group router.Group)) error

WithGroup will create a new route group for the given prefix

func (*Router) WithMethodNotAllowedHandler

func (r *Router) WithMethodNotAllowedHandler(handler interface{}) error

WithMethodNotAllowedHandler will set the not allowed handler for the router

func (*Router) WithMiddleware

func (r *Router) WithMiddleware(handler interface{}) error

WithMiddleware will add a middleware to the router

func (*Router) WithNotFoundHandler

func (r *Router) WithNotFoundHandler(handler interface{}) error

WithNotFoundHandler will set the not found handler for the router

func (*Router) WithRoute

func (r *Router) WithRoute(method string, path string, handler interface{}) error

WithRoute will add a new route with the given RouteMethod to the router

Jump to

Keyboard shortcuts

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