client

package
Version: v0.0.0-...-16b4722 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package http provides a wrapper of Go standard http module with recommended defaults values and context.

Get and Post requests

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := client.New(nil)
resp, err := c.Get(ctx, 'http://example.com')
...

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := client.Client(nil)
resp, err := c.Post(ctx, 'http://example.com', "text/plain", &buf)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client represents HTTP client to send request to server.

func New

func New(config *Config) *Client

New returns a new instances of Client. It sets the necessary defaults if configuration is nil. It will also set any missing fields with defaults variables.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (resp *http.Response, err error)

Get issues a GET request to the URL.

func (*Client) Post

func (c *Client) Post(ctx context.Context, url, contentType string, body io.Reader) (resp *http.Response, err error)

Post issues a POST request to the URL and sends a body to server.

type Config

type Config struct {
	// MaxIdleConns controls maximum of idle connections using keep-alive.
	MaxIdleConns int

	// Timeout specifies the time limit for a request including getting a response from server.
	Timeout time.Duration

	// KeepAlive specifies the interval between keep-alive probes.
	KeepAlive time.Duration

	// IdleConnTimeout is the maximum amount of time a keep-alive connection is kept open.
	IdleConnTimeout time.Duration

	// TLSHandshakeTimeout specifies the time limit to wait for a TLS handshake.
	TLSHandshakeTimeout time.Duration

	// ExpectContinueTimeout is the maximum amount of time to wait for a server first response.
	ExpectContinueTimeout time.Duration

	// TLSConfig specifies necessary TLS configuration.
	TLSConfig *tls.Config

	//EnableHTTP2 controls whether to use HTTP2
	EnableHTTP2 bool
}

Config represents the necessary configuration for a HTTP client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL