httpclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMaxAttemptsExceeded is returned when the maximum number of attempts is exceeded
	ErrMaxAttemptsExceeded = errors.New("maximum number of attempts exceeded")
	// ErrInvalidTransportType is returned when the transport type is invalid
	ErrInvalidTransportType = errors.New("invalid transport type")
)

Functions

func Apply

func Apply(c *http.Client, opts ...Option) error

Apply applies options to an existing client

func New

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

New builds a new *http.Client

Types

type Option

type Option interface {
	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

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 is a type of Option which configures the TLS configuration of the client

func (TLSOption) Apply

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

Apply implements Option

type TransportOption

type TransportOption func(transport *http.Transport) error

TransportOption configures the client's transport

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