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 ¶
- Constants
- type Matcher
- type Mux
- func Every(muxes ...*Mux) *Mux
- func Header(key, pattern string) *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 Some(muxes ...*Mux) *Mux
- func (m *Mux) AddMatcher(matchers ...Matcher) *Mux
- func (m *Mux) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler)
- func (m *Mux) If(matchers ...Matcher) *Mux
- func (m *Mux) Match(req *http.Request) bool
- func (m *Mux) Some(matchers ...Matcher) *Mux
- func (m *Mux) Use(handler interface{}) *Mux
- func (m *Mux) UseFinalHandler(handler http.Handler) *Mux
- func (m *Mux) UsePhase(phase string, handler interface{}) *Mux
Constants ¶
const Version = "0.1.0"
Version defines the current package semantic version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
Matcher represents the function interface implemented by matchers
func MatchHeader ¶
MatchHeader matches a given header key and value againts the request.
func MatchMethod ¶
MatchMethod matches the HTTP method name againts the request.
func MatchQuery ¶
MatchQuery matches a given query param againts the request.
type Mux ¶
type Mux struct { // Matchers stores a list of matcher functions. Matchers []Matcher // Layer stores the multiplexer middleware layer. Layer *layer.Layer }
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 Header ¶
Header returns a new multiplexer who matches an HTTP request header field based on the given key and regexp pattern.
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 (*Mux) AddMatcher ¶
AddMatcher adds a new matcher function in the current mumultiplexer matchers stack.
func (*Mux) HandleHTTP ¶
HandleHTTP 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) UseFinalHandler ¶
UseFinalHandler registers a new plugin in the middleware stack.