middleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package middleware provides a common handler middleware.

Index

Constants

This section is empty.

Variables

View Source
var DefaultGroupManager = manager.New[*Group]()

DefaultGroupManager is the default global manager of middleware groups.

View Source
var DefaultRegistry = registry.New[Middleware]()

DefaultRegistry is the global default registry of the middleware builder.

Functions

func BindConf

func BindConf(name string, dstconf, srcconf any) (err error)

BindConf builds the config dstconf of the middleware named name from srcconf.

scrconf may be one of types as follow:

  • map[string]any
  • json.RawMessage
  • []byte

func HandleGroup

func HandleGroup(c *core.Context, group string, next core.Handler)

HandleGroupWithGetter is a convenient function, which is equal to

HandleGroupWithGetter(c, DefaultGroupManager, group, next)

func HandleGroupWithGetter

func HandleGroupWithGetter(c *core.Context, g GroupGetter, group string, next core.Handler)

HandleGroupWithGetter forwards the request to the middleware group, which is got from the middleware group getter g by the group name, to handle.

Types

type Group

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

Group is used to manage a set of middlewares.

func NewGroup

func NewGroup(name string, mws ...Middleware) *Group

NewGroup returns a new middleware group, which also adds the middlewares if exists.

func (*Group) Handle

func (g *Group) Handle(c *core.Context, next core.Handler)

Handle handles the request with the middlewares, and forwards it to next.

func (*Group) Middlewares

func (g *Group) Middlewares() Middlewares

Middlewares returns all the middlewares.

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the group.

func (*Group) Reset

func (g *Group) Reset(mws ...Middleware)

Reset resets the middlewares to mws.

type GroupGetter

type GroupGetter interface {
	Get(name string) (g *Group, ok bool)
}

GroupGetter is used to get the middleware group by the name.

type Middleware

type Middleware interface {
	Handler(core.Handler) core.Handler
	Name() string
}

Middleware is the middleare to wrap the handler to return a new.

func New

func New(name string, config any, wrap MiddlewareFunc) Middleware

New returns a new middleware.

type MiddlewareFunc

type MiddlewareFunc func(next core.Handler) core.Handler

MiddlewareFunc is the middleware wrapping function.

func (MiddlewareFunc) Handler

func (f MiddlewareFunc) Handler(next core.Handler) core.Handler

Handler implements the interface Middleware.

type Middlewares

type Middlewares []Middleware

Middlewares represents a set of middlewares.

func (Middlewares) Handler

func (ms Middlewares) Handler(handler core.Handler) core.Handler

Handler wraps the handler with the middlewares and returns a new handler.

type Unwrapper

type Unwrapper interface {
	Unwrap() Middleware
}

Unwrapper is used to unwrap an inner middleware.

Directories

Path Synopsis
Package middlewares is used to register the builtin middlewares.
Package middlewares is used to register the builtin middlewares.
allow
Package allow provides a client-allowed middleware.
Package allow provides a client-allowed middleware.
auth
Package auth provides a common auth middleware based on the request header 'Authorization'.
Package auth provides a common auth middleware based on the request header 'Authorization'.
auth/forwardauth
Package forward provides a middleware that forward the auth to the external server.
Package forward provides a middleware that forward the auth to the external server.
block
Package block provides a client-blocked middleware.
Package block provides a client-blocked middleware.
cors
Package cors provides a CORS middleware.
Package cors provides a CORS middleware.
logger
Package provides a logger middleware to log the request.
Package provides a logger middleware to log the request.
processor
Package processor provides a processor middleware to handle the forwarding request and response.
Package processor provides a processor middleware to handle the forwarding request and response.
redirect
Package redirect provides a redirect middleware.
Package redirect provides a redirect middleware.
requestid
Package requestid provides a request id middleware based on the request header "X-Request-Id".
Package requestid provides a request id middleware based on the request header "X-Request-Id".

Jump to

Keyboard shortcuts

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