Documentation ¶
Overview ¶
Package middleware provides a common handler middleware.
Index ¶
- Variables
- func BindConf(name string, dstconf, srcconf any) (err error)
- func HandleGroup(c *core.Context, group string, next core.Handler)
- func HandleGroupWithGetter(c *core.Context, g GroupGetter, group string, next core.Handler)
- type Group
- type GroupGetter
- type Middleware
- type MiddlewareFunc
- type Middlewares
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
var DefaultGroupManager = manager.New[*Group]()
DefaultGroupManager is the default global manager of middleware groups.
var DefaultRegistry = registry.New[Middleware]()
DefaultRegistry is the global default registry of the middleware builder.
Functions ¶
func BindConf ¶
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 ¶
HandleGroupWithGetter is a convenient function, which is equal to
HandleGroupWithGetter(c, DefaultGroupManager, group, next)
func HandleGroupWithGetter ¶
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) Middlewares ¶
func (g *Group) Middlewares() Middlewares
Middlewares returns all the middlewares.
type GroupGetter ¶
GroupGetter is used to get the middleware group by the name.
type Middleware ¶
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 ¶
MiddlewareFunc is the middleware wrapping function.
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". |