httpcmw

package module
v0.0.0-...-14ea052 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2016 License: BSD-3-Clause Imports: 3 Imported by: 7

README

httpcmw GoDoc Build Status

Package httpcmw is a collection of bite-sized middleware with chaining support for HTTP clients (Doer, see http://0value.com/Let-the-Doer-Do-it). See the godoc for full documentation.

Installation

$ go get github.com/PuerkitoBio/httpcmw/...

Use -u to update, -t to install test dependencies.

License

The BSD 3-clause license, see LICENSE file.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 (github.com/go-kit/kit/log).

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.

Directories

Path Synopsis
Package headers defines a middleware that adds static headers to the requests.
Package headers defines a middleware that adds static headers to the requests.
Package logrequest implements a middleware that logs requests.
Package logrequest implements a middleware that logs requests.
Package requestid implements an HTTP client middleware that generates a random request ID.
Package requestid implements an HTTP client middleware that generates a random request ID.

Jump to

Keyboard shortcuts

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