timeouthttp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 4 Imported by: 24

README

go-timeout-httpclient

Yet another HTTP Client with configurable timeouts

Usage


import "github.com/pteich/go-timeout-httpclient"

httpClient := timeouthttp.NewClient(timeouthttp.Config{
    RequestTimeout: 5,
    ConnectTimeout: 5,
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPooledTransport

func DefaultPooledTransport(config Config) *http.Transport

func DefaultTransport

func DefaultTransport(config Config) *http.Transport

func New added in v0.2.0

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

New returns a new clean HTTP.Client with variable options set

func NewClient

func NewClient(config Config) *http.Client

NewClient returns a new clean HTTP.Client with timeouts (default 1s for connection and request), disabled idle connections and disabled keep-alives

func NewPooledClient

func NewPooledClient(config Config) *http.Client

NewPooledClient returns a new clean HTTP.Client with timeouts (default 1s for connection and request) and shared transport across hosts with keepalive on, you can set the number of idle connections per host with Config.MaxIdleConnsPerHost (default 1)

Types

type Config

type Config struct {
	ConnectTimeout            int
	RequestTimeout            int
	KeepAliveTimeout          int
	MaxIdleConnectionsPerHost int
	KeepAlive                 bool
}

Config defines timeouts and max idle connections per host if pooled transport is used all timeouts are seconds

type Option added in v0.2.0

type Option func(c *Config)

func WithConnectTimeout added in v0.2.0

func WithConnectTimeout(timeout int) Option

func WithKeepAliveTimeout added in v0.2.0

func WithKeepAliveTimeout(timeout int) Option

func WithMaxIdleConnections added in v0.2.0

func WithMaxIdleConnections(count int) Option

func WithRequestTimeout added in v0.2.0

func WithRequestTimeout(timeout int) Option

func WithTimeout added in v0.2.0

func WithTimeout(timeout int) Option

Jump to

Keyboard shortcuts

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