Back to

Package httpcmw

Latest Go to latest

The latest major version is .

Published: Aug 4, 2016 | License: BSD-3-Clause | Module:


Package httpcmw supports creating middleware chains for HTTP clients. It abstracts the *http.Client into a Doer interface and wraps middleware around the Do call.


type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)

Doer defines the method required for an HTTP client to execute requests. An *http.Client satisfies this interface.

func Wrap

func Wrap(d Doer, ws ...Wrapper) Doer

Wrap wraps the Doer d with the provided middleware ws. It returns a Doer that will call ws[0] -> ws[1] -> ... -> ws[n-1] -> d. Each Wrapper may stop the chain of calls by not calling the next Doer in the chain.

type DoerFunc

type DoerFunc func(*http.Request) (*http.Response, error)

DoerFunc is a function signature that satisfies the Doer interface.

func (DoerFunc) Do

func (fn DoerFunc) Do(req *http.Request) (*http.Response, error)

Do satisfies the Doer interface for a DoerFunc by calling the function.

type Logger

type Logger interface {
	Log(...interface{}) error

Logger defines the Log method that is used to log structured data, in tuples of alternating keys/values. The go-kit logger satisfies this interface (

type PrintfLogger

type PrintfLogger func(string, ...interface{})

PrintfLogger is an adapter to use Printf-style functions as a Logger in the middlewares that accept one. For example, the stdlib's log.Printf function can be used via this adapter.

func (PrintfLogger) Log

func (fn PrintfLogger) Log(args ...interface{}) error

Log implements Logger for the PrintfLogger function adapter.

type Wrapper

type Wrapper interface {
	Wrap(Doer) Doer

Wrapper defines the Wrap method required to build a middleware-style chain of calls.

type WrapperFunc

type WrapperFunc func(Doer) Doer

WrapperFunc is a function type that satisfies the Wrapper interface.

func (WrapperFunc) Wrap

func (fn WrapperFunc) Wrap(d Doer) Doer

Wrap satisfies the Wrapper interface for a WrapperFunc by calling the function.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier