httpclient

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: MIT Imports: 6 Imported by: 1

README

Go HTTP Client

Build Status Coverage Status Go Report Card GitHub release

Simple module for creating HTTP clients with timeouts and connection pool.

Description

Instead of copying and pasting the same snippet of code for creating http.Client with timeouts and connection pools, this module provides a simple package for create a client.

Usage

There are two ways for creating a HTTP client.

Default Client

The function CreateDefaultHttpClient() provides a HTTP client with timeouts set to 5 seconds, keep alive set to 30 seconds, TLS handshake timeout set to 5 seconds, idleConnection timeout set to 90 seconds, max idle connections is 100, and max idle connections per host is 100.

Specific Client

The function CreateHttpClient(timeout, keepAlive, tlsHandshakeTimeout, idleConnection time.Duration, idleConns, idleConnsPerHost int) allows the ability to tweak the specific timeouts and connection pool.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultHttpClient

func CreateDefaultHttpClient() *http.Client

CreateDefaultHttpClient creates a default http.Client.

Timeout set to 5 seconds, keep alive set to 30 seconds, TLS handshake timeout set to 5 seconds, idleConnection timeout set to 90 seconds, max idle connections is 100, and max idle connections per host is 100.

func CreateHttpClient

func CreateHttpClient(timeout, keepAlive, tlsHandshakeTimeout, idleConnection time.Duration, idleConns, idleConnsPerHost int) *http.Client

CreateHttpClient creates a http.Client from the specified timeouts and keep alive.

The client also has the maximum number of idle connections set to 100 and number of connections per host as 100.

func CreateOAuth2Client added in v1.0.2

func CreateOAuth2Client(clientId, clientSecret, accessTokenUri string) (*http.Client, error)

CreateOAuth2Client creates an OAuth2 http.Client from the provided credentials.

func CreateOAuth2Config added in v1.0.2

func CreateOAuth2Config(clientId, clientSecret, accessTokenUri string) (*clientcredentials.Config, error)

CreateOAuth2Config creates an OAuth2 config from the provided credentials.

Types

This section is empty.

Jump to

Keyboard shortcuts

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