gentleman.v2: gopkg.in/h2non/gentleman.v2/mux Index | Files

package mux

import "gopkg.in/h2non/gentleman.v2/mux"

Package mux implements an HTTP domain-specific traffic multiplexer with built-in matchers and features for easy plugin composition and activable logic.

Index

Package Files

compose.go matchers.go mux.go

type Matcher Uses

type Matcher func(ctx *c.Context) bool

Matcher represent the function interface implemented by matchers

type Mux Uses

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 Uses

func Error() *Mux

Error returns a new multiplexer who matches errors originated in the client or in the server.

func Host Uses

func Host(pattern string) *Mux

Host returns a new multiplexer who matches an HTTP request URL host based on the given regexp pattern.

func If Uses

func If(muxes ...*Mux) *Mux

If creates a new multiplexer that will be executed if all the mux matchers passes.

func Match Uses

func Match(matchers ...Matcher) *Mux

Match creates a new multiplexer based on a given matcher function.

func Method Uses

func Method(methods ...string) *Mux

Method returns a new multiplexer who matches an HTTP request based on the given method/s.

func New Uses

func New() *Mux

New creates a new multiplexer with default settings.

func Or Uses

func Or(muxes ...*Mux) *Mux

Or creates a new multiplexer that will be executed if at least one mux matcher passes.

func Path Uses

func Path(pattern string) *Mux

Path returns a new multiplexer who matches an HTTP request path based on the given regexp pattern.

func Query Uses

func Query(key, pattern string) *Mux

Query returns a new multiplexer who matches an HTTP request query param based on the given key and regexp pattern.

func RequestHeader Uses

func RequestHeader(key, pattern string) *Mux

RequestHeader returns a new multiplexer who matches an HTTP request header field based on the given key and regexp pattern.

func ResponseHeader Uses

func ResponseHeader(key, pattern string) *Mux

ResponseHeader returns a new multiplexer who matches an HTTP response header field based on the given key and regexp pattern.

func ServerError Uses

func ServerError() *Mux

ServerError returns a new multiplexer who matches response errors by the server.

func Status Uses

func Status(codes ...int) *Mux

Status returns a new multiplexer who matches an HTTP response status code based on the given status codes.

func StatusRange Uses

func StatusRange(start, end int) *Mux

StatusRange returns a new multiplexer who matches an HTTP response status code based on the given status range, including both numbers.

func Type Uses

func Type(kind string) *Mux

Type returns a new multiplexer who matches an HTTP response Content-Type header field based on the given type string.

func URL Uses

func URL(pattern string) *Mux

URL returns a new multiplexer who matches an HTTP request URL based on the given regexp pattern.

func (*Mux) AddMatcher Uses

func (m *Mux) AddMatcher(matchers ...Matcher) *Mux

AddMatcher adds a new matcher function in the current mumultiplexer matchers stack.

func (*Mux) Clone Uses

func (m *Mux) Clone() middleware.Middleware

Clone creates a new Middleware instance based on the current one.

func (*Mux) Flush Uses

func (m *Mux) Flush()

Flush flushes the plugins stack.

func (*Mux) GetStack Uses

func (m *Mux) GetStack() []plugin.Plugin

GetStack gets the current middleware plugins stack.

func (*Mux) Handler Uses

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 Uses

func (m *Mux) Match(ctx *c.Context) bool

Match matches the give Context againts a list of matchers and returns `true` if all the matchers passed.

func (*Mux) Run Uses

func (m *Mux) Run(phase string, ctx *c.Context) *c.Context

Run triggers the middleware call chain for the given phase.

func (*Mux) SetStack Uses

func (m *Mux) SetStack(stack []plugin.Plugin)

SetStack sets the middleware plugin stack overriding the existent one.

func (*Mux) Use Uses

func (m *Mux) Use(p plugin.Plugin) *Mux

Use registers a new plugin in the middleware stack.

func (*Mux) UseError Uses

func (m *Mux) UseError(fn c.HandlerFunc) *Mux

UseError registers a new error phase middleware handler.

func (*Mux) UseHandler Uses

func (m *Mux) UseHandler(phase string, fn c.HandlerFunc) *Mux

UseHandler registers a new error phase middleware handler.

func (*Mux) UseParent Uses

func (m *Mux) UseParent(parent middleware.Middleware) *Mux

UseParent attachs a parent middleware.

func (*Mux) UseRequest Uses

func (m *Mux) UseRequest(fn c.HandlerFunc) *Mux

UseRequest registers a new request phase middleware handler.

func (*Mux) UseResponse Uses

func (m *Mux) UseResponse(fn c.HandlerFunc) *Mux

UseResponse registers a new response phase middleware handler.

Package mux imports 6 packages (graph) and is imported by 3 packages. Updated 2020-02-18. Refresh now. Tools for package owners.