httpcmw: Index | Files | Directories

package httpcmw

import ""

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.


Package Files

httpcmw.go logger.go

type Doer Uses

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 Uses

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 Uses

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

DoerFunc is a function signature that satisfies the Doer interface.

func (DoerFunc) Do Uses

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

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

type Logger Uses

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 Uses

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 Uses

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

Log implements Logger for the PrintfLogger function adapter.

type Wrapper Uses

type Wrapper interface {
    Wrap(Doer) Doer

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

type WrapperFunc Uses

type WrapperFunc func(Doer) Doer

WrapperFunc is a function type that satisfies the Wrapper interface.

func (WrapperFunc) Wrap Uses

func (fn WrapperFunc) Wrap(d Doer) Doer

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


headersPackage headers defines a middleware that adds static headers to the requests.
logrequestPackage logrequest implements a middleware that logs requests.
requestidPackage requestid implements an HTTP client middleware that generates a random request ID.

Package httpcmw imports 3 packages (graph) and is imported by 5 packages. Updated 2018-06-11. Refresh now. Tools for package owners.