handler

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBalancerHandler added in v0.4.1

func NewBalancerHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)

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

func NewContentHandler(cfg tree.Map, _ logger.Logger) (fasthttp.RequestHandler, error)

NewContentHandler creates a new fasthttp.RequestHandler via Content.Handle.

func NewFS added in v0.1.0

func NewFS(cfg tree.Map) (*fasthttp.FS, error)

NewFS creates a fasthttp.FS. The specified cfg must have 'root' entry.

func NewFSHandler

func NewFSHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)

NewFSHandler creates a new fasthttp.RequestHandler via fasthttp.FS.

func NewHandler

func NewHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)

NewHandler creates a new fasthttp.RequestHandler.

func NewProxyHandler

func NewProxyHandler(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)

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

func NewContent(handlerCfg tree.Map) (*Content, error)

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

type NewHandlerFunc func(cfg tree.Map, l logger.Logger) (fasthttp.RequestHandler, error)

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.

Jump to

Keyboard shortcuts

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