v0.0.0-...-01100c3 Latest Latest

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

Go to latest
Published: Jan 22, 2018 License: MIT Imports: 7 Imported by: 0



Package clients is a set of utilities for creating and configuring instances of http.Client.

Clients are created with the New() function, which takes a set of Options to configure the client. Options implement common configuration recipes, like disabling server TLS verification, or setting a simple proxy.


c, err := clients.New(clients.SkipVerify(), clients.Timeout(10 * time.Seconds))



This section is empty.


This section is empty.


func New

func New(opts ...Option) (*http.Client, error)

New builds a new *http.Client. With no arguments, the client will be configured identically to the http.DefaultClient and http.DefaultTransport, but will be different instances (so they can be further modified without having a global effect).

The client can be further configured by passing Options.


type Option

type Option interface {

	// Apply is called when constructing an http.Client.  Apply
	// should make some configuration change to the argument.
	// The client argument will not be nil.
	Apply(*http.Client) error

Option is a configuration option for building an http.Client.

func CookieJar

func CookieJar(opts *cookiejar.Options) Option

CookieJar installs a cookie jar into the client, configured with the options argument.

The argument will be nil.

func MaxRedirects

func MaxRedirects(max int) Option

MaxRedirects configures the max number of redirects the client will perform before giving up.

func NoRedirects

func NoRedirects() Option

NoRedirects configures the client to no perform any redirects.

func ProxyFunc

func ProxyFunc(f func(request *http.Request) (*url.URL, error)) Option

ProxyFunc configures the client's proxy function.

func ProxyURL

func ProxyURL(proxyURL string) Option

ProxyURL will proxy all calls through a single proxy URL.

func SkipVerify

func SkipVerify(skip bool) Option

SkipVerify sets the TLS config's InsecureSkipVerify flag.

func Timeout

func Timeout(d time.Duration) Option

Timeout configures the client's Timeout property.

type OptionFunc

type OptionFunc func(*http.Client) error

OptionFunc adapts a function to the Option interface.

func (OptionFunc) Apply

func (f OptionFunc) Apply(c *http.Client) error

Apply implements Option.

type TLSOption

type TLSOption func(c *tls.Config) error

A TLSOption configures the TLS configuration of the client.

The argument will never be nil. A new, default config will be created in necessary.

func (TLSOption) Apply

func (f TLSOption) Apply(c *http.Client) error

Apply implements Option.

type TransportOption

type TransportOption func(transport *http.Transport) error

A TransportOption configures the client's transport.

The argument will never be nil. TransportOption will create a default http.Transport (configured identically to the http.DefaultClient.Transport) if necessary.

If the client's transport is not a *http.Transport, an error is returned.

func (TransportOption) Apply

func (f TransportOption) Apply(c *http.Client) error

Apply implements Option.

Jump to

Keyboard shortcuts

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