httpClient

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default is an instance of net/http.Client that has
	// retry enabled and is used if Client.Client is nil.
	Default = New(&Options{
		RetryTimeMax: 45 * time.Second,
	})
)

Functions

func New

func New(options *Options) *http.Client

New creates a net/http.Client with options from Options.

func Transport

func Transport(options *Options) *http.Transport

Transport creates a net/http.Transport with options from Options.

Types

type Options

type Options struct {
	// Value for net.Dialer.Timeout.
	Timeout time.Duration `envconfig:"TIMEOUT"`
	// Value for net.Dialer.KeepAlive.
	KeepAlive time.Duration `envconfig:"KEEP_ALIVE"`
	// Value for net/http.Transport.TLSHandshakeTimeout.
	TLSHandshakeTimeout time.Duration `envconfig:"TLS_HANDSHAKE_TIMEOUT"`
	// Value for crypto/tls.Config.TLSSkipVerify.
	TLSSkipVerify bool `envconfig:"TLS_SKIP_VERIFY"`
	// Maximum time while Dialer reties are made.
	// Default is 0. Which means that Retrying is disabled by default.
	RetryTimeMax time.Duration `envconfig:"RETRY_TIME_MAX"`
	// Maximum time between two retries.
	// Default is 2 seconds.
	RetrySleepMax time.Duration `envconfig:"RETRY_SLEEP_MAX"`
	// Time for first retry. Every other is doubled until RetrySleepMax.
	// Default is 200 milliseconds.
	RetrySleepBase time.Duration `envconfig:"RETRY_SLEEP_BASE"`
}

Options is structure that passes optional variables to New function.

func (Options) MarshalJSON

func (o Options) MarshalJSON() ([]byte, error)

MarshalJSON implements of json.Marshaler interface. It marshals string representations of time.Duration.

func (Options) MarshalYAML

func (o Options) MarshalYAML() (interface{}, error)

MarshalYAML implements of yaml.Marshaler interface. It marshals string representations of time.Duration.

func (*Options) UnmarshalJSON

func (o *Options) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unamrshaler interface. It parses time.Duration as strings.

func (*Options) UnmarshalYAML

func (o *Options) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unamrshaler interface. It parses time.Duration as strings.

Jump to

Keyboard shortcuts

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