Documentation ¶
Overview ¶
Package mux implements an HTTP domain-specific traffic multiplexer with built-in matchers and features for easy plugin composition and activable logic.
Index ¶
- type Matcher
- type Mux
- func Error() *Mux
- func Host(pattern string) *Mux
- func If(muxes ...*Mux) *Mux
- func Match(matchers ...Matcher) *Mux
- func Method(methods ...string) *Mux
- func New() *Mux
- func Or(muxes ...*Mux) *Mux
- func Path(pattern string) *Mux
- func Query(key, pattern string) *Mux
- func RequestHeader(key, pattern string) *Mux
- func ResponseHeader(key, pattern string) *Mux
- func ServerError() *Mux
- func Status(codes ...int) *Mux
- func StatusRange(start, end int) *Mux
- func Type(kind string) *Mux
- func URL(pattern string) *Mux
- func (m *Mux) AddMatcher(matchers ...Matcher) *Mux
- func (m *Mux) Clone() middleware.Middleware
- func (m *Mux) Flush()
- func (m *Mux) GetStack() []plugin.Plugin
- func (m *Mux) Handler() c.HandlerFunc
- func (m *Mux) Match(ctx *c.Context) bool
- func (m *Mux) Run(phase string, ctx *c.Context) *c.Context
- func (m *Mux) SetStack(stack []plugin.Plugin)
- func (m *Mux) Use(p plugin.Plugin) *Mux
- func (m *Mux) UseError(fn c.HandlerFunc) *Mux
- func (m *Mux) UseHandler(phase string, fn c.HandlerFunc) *Mux
- func (m *Mux) UseParent(parent middleware.Middleware) *Mux
- func (m *Mux) UseRequest(fn c.HandlerFunc) *Mux
- func (m *Mux) UseResponse(fn c.HandlerFunc) *Mux
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mux ¶
type Mux struct { // Mux also implements a plugin capable interface. *plugin.Layer // Matchers stores a list of matcher functions. Matchers []Matcher // Middleware stores the multiplexer middleware layer. Middleware middleware.Middleware }
Mux is a HTTP request/response/error multiplexer who implements both middleware and plugin interfaces. It has been designed for easy plugin composition based on HTTP matchers/filters.
func Error ¶
func Error() *Mux
Error returns a new multiplexer who matches errors originated in the client or in the server.
func Host ¶
Host returns a new multiplexer who matches an HTTP request URL host based on the given regexp pattern.
func Method ¶
Method returns a new multiplexer who matches an HTTP request based on the given method/s.
func Path ¶
Path returns a new multiplexer who matches an HTTP request path based on the given regexp pattern.
func Query ¶
Query returns a new multiplexer who matches an HTTP request query param based on the given key and regexp pattern.
func RequestHeader ¶
RequestHeader returns a new multiplexer who matches an HTTP request header field based on the given key and regexp pattern.
func ResponseHeader ¶
ResponseHeader returns a new multiplexer who matches an HTTP response header field based on the given key and regexp pattern.
func ServerError ¶
func ServerError() *Mux
ServerError returns a new multiplexer who matches response errors by the server.
func Status ¶
Status returns a new multiplexer who matches an HTTP response status code based on the given status codes.
func StatusRange ¶
StatusRange returns a new multiplexer who matches an HTTP response status code based on the given status range, including both numbers.
func Type ¶
Type returns a new multiplexer who matches an HTTP response Content-Type header field based on the given type string.
func URL ¶
URL returns a new multiplexer who matches an HTTP request URL based on the given regexp pattern.
func (*Mux) AddMatcher ¶
AddMatcher adds a new matcher function in the current mumultiplexer matchers stack.
func (*Mux) Clone ¶
func (m *Mux) Clone() middleware.Middleware
Clone creates a new Middleware instance based on the current one.
func (*Mux) Handler ¶
func (m *Mux) Handler() c.HandlerFunc
Handler returns the function handler to match an incoming HTTP transacion and trigger the equivalent middleware phase.
func (*Mux) Match ¶
Match matches the give Context againts a list of matchers and returns `true` if all the matchers passed.
func (*Mux) UseError ¶
func (m *Mux) UseError(fn c.HandlerFunc) *Mux
UseError registers a new error phase middleware handler.
func (*Mux) UseHandler ¶
func (m *Mux) UseHandler(phase string, fn c.HandlerFunc) *Mux
UseHandler registers a new error phase middleware handler.
func (*Mux) UseParent ¶
func (m *Mux) UseParent(parent middleware.Middleware) *Mux
UseParent attachs a parent middleware.
func (*Mux) UseRequest ¶
func (m *Mux) UseRequest(fn c.HandlerFunc) *Mux
UseRequest registers a new request phase middleware handler.
func (*Mux) UseResponse ¶
func (m *Mux) UseResponse(fn c.HandlerFunc) *Mux
UseResponse registers a new response phase middleware handler.