Documentation ¶
Index ¶
- func NewBalancerHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)
- func NewContentHandler(cfg tree.Map, _ logger.Logger) (fasthttp.RequestHandler, error)
- func NewFS(cfg tree.Map) (*fasthttp.FS, error)
- func NewFSHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)
- func NewHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)
- func NewProxyHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)
- func RegisterNewHandlerFunc(typeName string, fn NewHandlerFunc)
- func SendDefaultError(ctx *fasthttp.RequestCtx)
- type Content
- type ErrorPages
- type NewHandlerFunc
- type ServerHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBalancerHandler ¶ added in v0.4.1
NewBalancerHandler creates a new a proxy handler that proxies to backend url. This handler using https://github.com/zehuamama/balancer. The specified cfg supports following keys.
- urls - backend url list
- algorithm - ip-hash, consistent-hash, p2c, random, round-robin, least-load, bounded
- healthCheckInterval - health-check interval (seconds)
NOTE: If NewProxyHandler supports multiple URLs, this implementation may be deprecated.
func NewContentHandler ¶ added in v0.3.3
NewContentHandler creates a new fasthttp.RequestHandler via Content.Handle.
func NewFSHandler ¶
NewFSHandler creates a new fasthttp.RequestHandler via fasthttp.FS.
func NewHandler ¶
NewHandler creates a new fasthttp.RequestHandler.
func NewProxyHandler ¶
NewProxyHandler creates a new a proxy handler that proxies to backend url. The specified cfg must have 'url' entry.
func RegisterNewHandlerFunc ¶
func RegisterNewHandlerFunc(typeName string, fn NewHandlerFunc)
RegisterNewHandlerFunc registers a NewHandlerFunc with the specified type name.
func SendDefaultError ¶ added in v0.3.7
func SendDefaultError(ctx *fasthttp.RequestCtx)
SendDefaultError sends default error page using ctx.Response.StatusCode(). It works as fasthttp.RequestHandler. If the provided ctx has response body, it does nothing.
Types ¶
type Content ¶ added in v0.3.3
type Content struct {
// contains filtered or unexported fields
}
Content represents a handler that provides a simple content.
func NewContent ¶ added in v0.3.3
NewContent creates a new Content that provides a simple content. The handlerCfg can be specified 'body' string and 'headers' map.
func (*Content) Handle ¶ added in v0.3.3
func (h *Content) Handle(ctx *fasthttp.RequestCtx)
Handle sets headers and body to the provided ctx.
type ErrorPages ¶
type ErrorPages struct {
// contains filtered or unexported fields
}
ErrorPages represents a handler that provides custom error pages.
func NewErrorPages ¶
func NewErrorPages(root string, statusToPath map[string]string) *ErrorPages
NewErrorPages creates a new ErrorPages. The statusToPath maps from a http status text to a path of error page. A http status text can be contain 'x' as wildcard. (eg. '404', '40x') If 'root' is specified in statusToPath, it overrides the default root.
func (*ErrorPages) Handle ¶
func (p *ErrorPages) Handle(ctx *fasthttp.RequestCtx)
type NewHandlerFunc ¶
NewHandlerFunc is a function that creates a new fasthttp.RequestHandler.
type ServerHandler ¶ added in v0.3.3
type ServerHandler interface { // Config returns the config.Config.Server. Config() tree.Map // Logger returns a logger. Logger() logger.Logger // Handle handles the provided request. Handle(ctx *fasthttp.RequestCtx) // HandleError implements fasthttp.Server.ErrorHandler. HandleError(ctx *fasthttp.RequestCtx, err error) // Close closes the server. Close() error }
ServerHandler is an interface that defines the methods to handle a server.
func NewServerHandler ¶ added in v0.3.3
func NewServerHandler(cfgs []config.Config) (ServerHandler, error)
NewServerHandler creates a new ServerHandler by the provided cfgs.