Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthFunc ¶
type AuthFunc func(ctx *fasthttp.RequestCtx) bool
AuthFunc is your custom auth function type
type Middleware ¶
type Middleware func(h fasthttp.RequestHandler) fasthttp.RequestHandler
Middleware is a function which receive a fasthttp.RequestHandler then return a fasthttp.RequestHandler.
func NewAuthMiddleware ¶
func NewAuthMiddleware(authFunc AuthFunc) Middleware
NewAuthMiddleware accepts a customer auth function and then returns a middleware which only accepts auth passed request. If auth function returns false, it will term the HTTP request and response 403 status code
func NewLogMiddleware ¶
func NewLogMiddleware(logger *zap.Logger, xRealIp bool) Middleware
NewLogMiddleware returns a middleware which log code(status code), time(response time), method(request method), path(request URL ath), addr(remote address). if the status code is 2xx, the log level is info, otherwise, the log level is warn. if your app is behind of Nginx, you may meed to set xRealIp to True so that get an really remote address.
func NewPrometheusMiddleware ¶
func NewPrometheusMiddleware(bindAddr string, logger *zap.Logger) Middleware
NewPrometheusMiddleware return a middleware which can be used by prometheus(https://github.com/prometheus/prometheus) collecting metrics. The prometheus is a monitoring system and time series database.
func NewRecoverMiddleware ¶
func NewRecoverMiddleware(logger *zap.Logger) Middleware
NewRecoverMiddleware return a middleware which can let app recover from a panic in request handler. panic stack info will appear on the field named "stacktrace" in the log line
type MiddlewareOnion ¶
type MiddlewareOnion struct {
// contains filtered or unexported fields
}
MiddlewareOnion represent the middleware like an onion, the bigger index of middleware in MiddlewareOnion.layers locate at outside
func NewMiddlewareOnion ¶
func NewMiddlewareOnion(middlewares ...Middleware) MiddlewareOnion
NewMiddlewareOnion returns a middleware onion with given middlewares
func NewNormalMiddlewareOnion ¶
func NewNormalMiddlewareOnion(authFunc AuthFunc, xRealIp bool, logger *zap.Logger) MiddlewareOnion
NewNormalMiddlewareOnion returns a normal middleware onion. recover -> auth -> log. the type of AuthFunc is "func(ctx *fasthttp.RequestCtx) bool". if your app is behind of Nginx, you may meed to set xRealIp to True so that get an actual remote address.
func (MiddlewareOnion) Append ¶
func (o MiddlewareOnion) Append(middlewares ...Middleware) MiddlewareOnion
Append copy all middleware layers to newLayers, then append middlewares to newLayers, then return a new middleware onion.
func (MiddlewareOnion) Apply ¶
func (o MiddlewareOnion) Apply(h fasthttp.RequestHandler) fasthttp.RequestHandler
Apply apply the middleware onion to a fasthttp.RequestHandler