Documentation ¶
Index ¶
- Constants
- func AcquireURL(uri *fasthttp.URI) *stdUrl.URL
- func B2S(b []byte) string
- func ConvertToFastHTTPHandler(handler RequestHandler) fasthttp.RequestHandler
- func ReleaseCtx(ctx *Ctx)
- func ReleaseURL(url *stdUrl.URL)
- func S2B(s string) (b []byte)
- type Config
- type Ctx
- func (ctx *Ctx) Defer(deferFunc func())
- func (ctx *Ctx) JSONBlobResponse(body []byte, statusCode ...int)
- func (ctx *Ctx) JSONInterfaceResponse(data JSONInterface, statusCode ...int)
- func (ctx *Ctx) Next()
- func (ctx *Ctx) PathName() string
- func (ctx *Ctx) RequestID() []byte
- func (ctx *Ctx) URL() *stdUrl.URL
- type JSONInterface
- type Red
- func (r Red) DELETE(path string, handlers ...RequestHandler)
- func (r Red) Defer(handlers ...RequestHandler)
- func (r Red) GET(path string, handlers ...RequestHandler)
- func (r Red) HEAD(path string, handlers ...RequestHandler)
- func (r Red) Handle(method, path string, handlers ...RequestHandler)
- func (r Red) Handler() fasthttp.RequestHandler
- func (r Red) NewGroup(path string) Router
- func (r *Red) NewVirtualHost(hostName string) Router
- func (r Red) PATCH(path string, handlers ...RequestHandler)
- func (r Red) POST(path string, handlers ...RequestHandler)
- func (r Red) PUT(path string, handlers ...RequestHandler)
- func (r *Red) Serve(ln net.Listener) error
- func (r *Red) Shutdown()
- func (r Red) TRACE(path string, handlers ...RequestHandler)
- func (r Red) Use(handlers ...RequestHandler)
- type RequestHandler
- type Router
Constants ¶
const (
XRequestIDHeader = "X-Request-ID"
)
Variables ¶
This section is empty.
Functions ¶
func AcquireURL ¶ added in v1.0.0
AcquirURL returns an url instance from pool
The returned URL may be passed to ReleaseURL when it is no longer needed. It is forbidden accessing url after releasing it
func B2S ¶ added in v1.0.0
B2S converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func ConvertToFastHTTPHandler ¶
func ConvertToFastHTTPHandler(handler RequestHandler) fasthttp.RequestHandler
func ReleaseCtx ¶
func ReleaseCtx(ctx *Ctx)
ReleaseCtx returns ctx acquired via AcquireCtx to context pool
It is forbidden accessing ctx after releasing it
func ReleaseURL ¶ added in v1.0.0
ReleaseURL returns URL acquired via AcquireURL to pool.
It is forbidden accessing url after releasing it
Types ¶
type Config ¶
type Config struct { //FastHTTP Settings ErrorHandler func(*Ctx, error) Name string Concurrency int DisableKeepalive bool ReadBufferSize int WriteBufferSize int ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration MaxConnsPerIP int MaxRequestsPerConn int MaxKeepaliveDuration time.Duration TCPKeepalive bool TCPKeepalivePeriod time.Duration MaxRequestBodySize int ReduceMemoryUsage bool GetOnly bool DisablePreParseMultipartForm bool LogAllErrors bool DisableHeaderNamesNormalizing bool SleepWhenConcurrencyLimitsExceeded time.Duration NoDefaultServerHeader bool NoDefaultDate bool NoDefaultContentType bool ConnState func(net.Conn, fasthttp.ConnState) Logger fasthttp.Logger KeepHijackedConns bool //Router Settigs SaveMatchedRoutePath bool GlobalOPTIONS RequestHandler NotFound RequestHandler MethodNotAllowed RequestHandler PanicHandler func(*Ctx, interface{}) }
type Ctx ¶
type Ctx struct { *fasthttp.RequestCtx // contains filtered or unexported fields }
Ctx context wrapper of fasthttp.RequestCtx to adds extra funtionality
func AcquireCtx ¶
func AcquireCtx(ctx *fasthttp.RequestCtx) *Ctx
AcquireCtx returns an empty Ctx instance from context pool
The returned Ctx instance may be passed to ReleaseCtx when it is no longer needed. It is forbidden accessing ctx after releasing it
func (*Ctx) Defer ¶ added in v1.0.0
func (ctx *Ctx) Defer(deferFunc func())
Defer appends given function to defer functions list
defer functions will be executed after defer middlewares's executions.
func (*Ctx) JSONBlobResponse ¶
func (*Ctx) JSONInterfaceResponse ¶
func (ctx *Ctx) JSONInterfaceResponse(data JSONInterface, statusCode ...int)
func (*Ctx) Next ¶
func (ctx *Ctx) Next()
When next used, the next handler will be executed after the current handler's execution.
type JSONInterface ¶
type Red ¶
type Red struct {
// contains filtered or unexported fields
}
func (Red) DELETE ¶ added in v1.0.0
func (r Red) DELETE(path string, handlers ...RequestHandler)
DELETE is a shortcut for router.Handle(fasthttp.MethodDelete, path, handlers)
func (Red) Defer ¶ added in v1.0.0
func (r Red) Defer(handlers ...RequestHandler)
Defer registers given handlers to router Given handlers will be executed after middlewares and handlers by given order
func (Red) GET ¶ added in v1.0.0
func (r Red) GET(path string, handlers ...RequestHandler)
GET is a shortcut for router.Handle(fasthttp.MethodGet, path, handlers)
func (Red) HEAD ¶ added in v1.0.0
func (r Red) HEAD(path string, handlers ...RequestHandler)
HEAD is a shortcut for router.Handle(fasthttp.MethodHead, path, handlers)
func (Red) Handle ¶ added in v1.0.0
func (r Red) Handle(method, path string, handlers ...RequestHandler)
Handle registers given request handlers with the given path and method There are shortcuts for some methods you can use them.
func (Red) Handler ¶ added in v1.0.0
func (r Red) Handler() fasthttp.RequestHandler
Handler gives routers request handler. Returns un-nil function only if the router is a virtual host router.
func (*Red) NewVirtualHost ¶ added in v1.0.0
NewVirtualHost creates a virtual host for given hostName.
func (Red) PATCH ¶ added in v1.0.0
func (r Red) PATCH(path string, handlers ...RequestHandler)
PATCH is a shortcut for router.Handle(fasthttp.MethodPatch, path, handlers)
func (Red) POST ¶ added in v1.0.0
func (r Red) POST(path string, handlers ...RequestHandler)
POST is a shortcut for router.Handle(fasthttp.MethodPost, path, handlers)
func (Red) PUT ¶ added in v1.0.0
func (r Red) PUT(path string, handlers ...RequestHandler)
PUT is a shortcut for router.Handle(fasthttp.MethodPut, path, handlers)
func (Red) TRACE ¶ added in v1.0.0
func (r Red) TRACE(path string, handlers ...RequestHandler)
TRACE is a shortcut for router.Handle(fasthttp.MethodTrace, path, handlers)
func (Red) Use ¶ added in v1.0.0
func (r Red) Use(handlers ...RequestHandler)
Use registers given middleware handlers to router Given handlers will be executed by given order
type RequestHandler ¶
type RequestHandler func(*Ctx)
func ConvertFastHTTPHandler ¶ added in v1.0.0
func ConvertFastHTTPHandler(handler fasthttp.RequestHandler) RequestHandler
func ConvertStdHTTPHandler ¶ added in v1.0.0
func ConvertStdHTTPHandler(handler http.HandlerFunc) RequestHandler
type Router ¶
type Router interface { // Handle registers given request handlers with the given path and method // There are shortcuts for some methods you can use them. Handle(method string, path string, handlers ...RequestHandler) // Use registers given middleware handlers to router // Given handlers will be executed by given order Use(handlers ...RequestHandler) // Defer registers given handlers to router // Given handlers will be executed after middlewares and handlers by given order Defer(handlers ...RequestHandler) // GET is a shortcut for router.Handle(fasthttp.MethodGet, path, handlers) GET(path string, handlers ...RequestHandler) // POST is a shortcut for router.Handle(fasthttp.MethodPost, path, handlers) POST(path string, handlers ...RequestHandler) // PUT is a shortcut for router.Handle(fasthttp.MethodPut, path, handlers) PUT(path string, handlers ...RequestHandler) // PATCH is a shortcut for router.Handle(fasthttp.MethodPatch, path, handlers) PATCH(path string, handlers ...RequestHandler) // DELETE is a shortcut for router.Handle(fasthttp.MethodDelete, path, handlers) DELETE(path string, handlers ...RequestHandler) // HEAD is a shortcut for router.Handle(fasthttp.MethodHead, path, handlers) HEAD(path string, handlers ...RequestHandler) // TRACE is a shortcut for router.Handle(fasthttp.MethodTrace, path, handlers) TRACE(path string, handlers ...RequestHandler) // Handler gives routers request handler. // Returns un-nil function only if the router is a virtual host router. Handler() fasthttp.RequestHandler // NewGroup creates a subrouter for given path. NewGroup(path string) Router }