Documentation ¶
Overview ¶
Package middleware defines a http handler middleware.
Index ¶
- Variables
- func GetPriority(m Middleware) int
- func Sort(ms []Middleware)
- type Manager
- func (m *Manager) Append(ms ...Middleware)
- func (m *Manager) AppendFunc(ms ...MiddlewareFunc)
- func (m *Manager) Handler(handler http.Handler) http.Handler
- func (m *Manager) Insert(ms ...Middleware)
- func (m *Manager) InsertFunc(ms ...MiddlewareFunc)
- func (m *Manager) Middlewares() Middlewares
- func (m *Manager) Reset(ms ...Middleware)
- func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Manager) SetHandler(handler http.Handler)
- type Middleware
- type MiddlewareFunc
- type Middlewares
- func (ms Middlewares) Append(m ...Middleware) Middlewares
- func (ms Middlewares) AppendFunc(m ...MiddlewareFunc) Middlewares
- func (ms Middlewares) Clone() Middlewares
- func (ms Middlewares) Handler(next http.Handler) http.Handler
- func (ms Middlewares) Insert(m ...Middleware) Middlewares
- func (ms Middlewares) InsertFunc(m ...MiddlewareFunc) Middlewares
- func (ms Middlewares) Sort()
Constants ¶
This section is empty.
Variables ¶
var DefaultMiddlewares = Middlewares{ New("rootpath", 0, path.Repsond204("/")), New("requestid", 10, requestid.RequestId), New("context", 20, context.Context), New("logger", 30, logger.Logger), New("recover", 40, recover.Recover), }
DefaultMiddlewares is a set of the default middlewares.
Functions ¶
func GetPriority ¶ added in v0.49.0
func GetPriority(m Middleware) int
GetPriority returns the priority of the middleware if it has implemented
interface{ Priority() int }
Or, return 0 instead.
NOTICE: the smaller the value, the high the priority.
func Sort ¶ added in v0.43.0
func Sort(ms []Middleware)
Sort sorts a set of middlewares by the priority from high to low.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is used to manage a set of the middlewares.
func NewManager ¶
NewManager returns a new middleware manager.
func (*Manager) Append ¶ added in v0.42.0
func (m *Manager) Append(ms ...Middleware)
Append appends the new middlewares.
func (*Manager) AppendFunc ¶ added in v0.43.0
func (m *Manager) AppendFunc(ms ...MiddlewareFunc)
AppendFunc appends the new function middlewares.
func (*Manager) Handler ¶ added in v0.42.0
Handler wraps the http handler with the added middlewares, and return a new http handler.
func (*Manager) Insert ¶ added in v0.43.0
func (m *Manager) Insert(ms ...Middleware)
Insert inserts the new middlewares to the front.
func (*Manager) InsertFunc ¶ added in v0.43.0
func (m *Manager) InsertFunc(ms ...MiddlewareFunc)
InsertFunc inserts the new function middlewares to the front.
func (*Manager) Middlewares ¶ added in v0.42.0
func (m *Manager) Middlewares() Middlewares
Middlewares returns the added middlewares.
func (*Manager) Reset ¶
func (m *Manager) Reset(ms ...Middleware)
Reset resets the middlewares to ms.
func (*Manager) ServeHTTP ¶
func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the interface http.Handler.
func (*Manager) SetHandler ¶
SetHandler resets the http handler.
type Middleware ¶
Middleware is a http handler middleware.
func New ¶ added in v0.42.0
func New(name string, priority int, mfunc MiddlewareFunc) Middleware
New returns a new named priority middleware, which has the methods as follows:
Name() string Priority() int
For the priority, the smaller the value, the higher the priority.
type MiddlewareFunc ¶ added in v0.42.0
MiddlewareFunc is the middleware function.
type Middlewares ¶
type Middlewares []Middleware
Middlewares is a set of middlewares.
func (Middlewares) Append ¶ added in v0.42.0
func (ms Middlewares) Append(m ...Middleware) Middlewares
Append appends a set of middlewares and return a new middleware slice.
func (Middlewares) AppendFunc ¶ added in v0.43.0
func (ms Middlewares) AppendFunc(m ...MiddlewareFunc) Middlewares
AppendFunc appends a set of function middlewares and return a new middleware slice.
func (Middlewares) Clone ¶ added in v0.4.0
func (ms Middlewares) Clone() Middlewares
Clone clones itself to a new middlewares.
func (Middlewares) Handler ¶
func (ms Middlewares) Handler(next http.Handler) http.Handler
Handler implements the interface Middleware.
func (Middlewares) Insert ¶ added in v0.43.0
func (ms Middlewares) Insert(m ...Middleware) Middlewares
Insert inserts a set of middlewares into the front and return a new middleware slice.
func (Middlewares) InsertFunc ¶ added in v0.43.0
func (ms Middlewares) InsertFunc(m ...MiddlewareFunc) Middlewares
InsertFunc inserts a set of function middlewares into the front and return a new middleware slice.
func (Middlewares) Sort ¶ added in v0.49.0
func (ms Middlewares) Sort()
Sort sorts itself by the priority from high to low.
Directories ¶
Path | Synopsis |
---|---|
Package context provides a context middleware to set the Context into the request.
|
Package context provides a context middleware to set the Context into the request. |
Package cors provides a CORS middleware.
|
Package cors provides a CORS middleware. |
Package logger provides a logger middleware to log the http request.
|
Package logger provides a logger middleware to log the http request. |
Package path provides a middleware to respond to the given path.
|
Package path provides a middleware to respond to the given path. |
Package recover provides a recover middleware to wrap and log the panic.
|
Package recover provides a recover middleware to wrap and log the panic. |
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". |