v2.0.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2017 License: MIT, MIT Imports: 3 Imported by: 9


gentleman/middleware Build Status GoDoc API Go Report Card

middleware package implements a simple middleware layer especially designed for HTTP client domain and full HTTP request/response live cycle.


go get -u gopkg.in/h2non/gentleman.v2/middleware


See godoc reference.


MIT - Tomas Aparicio



Package middleware implements an HTTP client domain-specific phase-oriented middleware layer used internally by gentleman packages.



This section is empty.


This section is empty.


This section is empty.


type Layer

type Layer struct {
	// contains filtered or unexported fields

Layer type represent an HTTP domain specific middleware layer with inheritance support.

func New

func New() *Layer

New creates a new middleware layer.

func (*Layer) Clone

func (s *Layer) Clone() Middleware

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

func (*Layer) Flush

func (s *Layer) Flush()

Flush flushes the plugins stack.

func (*Layer) GetStack

func (s *Layer) GetStack() []plugin.Plugin

GetStack gets the current middleware plugins stack.

func (*Layer) Run

func (s *Layer) Run(phase string, ctx *c.Context) *c.Context

Run triggers the middleware call chain for the given phase.

func (*Layer) SetStack

func (s *Layer) SetStack(stack []plugin.Plugin)

SetStack sets the middleware plugin stack overriding the existent one.

func (*Layer) Use

func (s *Layer) Use(plugin plugin.Plugin) Middleware

Use registers a new plugin to the middleware stack.

func (*Layer) UseError

func (s *Layer) UseError(fn c.HandlerFunc) Middleware

UseError registers a new error phase middleware handler.

func (*Layer) UseHandler

func (s *Layer) UseHandler(phase string, fn c.HandlerFunc) Middleware

UseHandler registers a phase specific plugin handler in the middleware stack.

func (*Layer) UseParent

func (s *Layer) UseParent(parent Middleware) Middleware

UseParent attachs a parent middleware.

func (*Layer) UseRequest

func (s *Layer) UseRequest(fn c.HandlerFunc) Middleware

UseRequest registers a new request phase middleware handler.

func (*Layer) UseResponse

func (s *Layer) UseResponse(fn c.HandlerFunc) Middleware

UseResponse registers a new response phase middleware handler.

type Middleware

type Middleware interface {
	// Use method is used to register a new plugin in the middleware stack.
	Use(plugin.Plugin) Middleware

	// UseError is used to register a new error phase middleware function handler.
	UseError(c.HandlerFunc) Middleware

	// UseRequest is used to register a new request phase middleware function handler.
	UseRequest(c.HandlerFunc) Middleware

	// UseResposne is used to register a new resposne phase middleware function handler.
	UseResponse(c.HandlerFunc) Middleware

	// UseHandler is used to register a new phase specific middleware function handler.
	UseHandler(string, c.HandlerFunc) Middleware

	// Run is used to dispatch the middleware call chain for a specific phase.
	Run(string, *c.Context) *c.Context

	// UseParent defines a parent middleware for easy inheritance.
	UseParent(Middleware) Middleware

	// Clone is used to created a new clone of the existent middleware.
	Clone() Middleware

	// Flush is used to flush the middleware stack.

	// GetStack is used to retrieve an array of registered plugins.
	GetStack() []plugin.Plugin

	// SetStack is used to override the stack of registered plugins.

Middleware especifies the required interface that must be implemented by middleware capable interfaces.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL