client

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package client provides HTTP client related syntactic sugar.

* GET call with context

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

resp := client.MustGetWithContext(ctx, "https://domain.tld")
defer resp.Body.Close()

* GET call with tar.gz content

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

client.MustGetAndUntarWithContext(ctx, "https://domain.tld", "/path/to/extract")

* GET call with zip content

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

client.MustGetAndUnzipWithContext(ctx, "https://domain.tld", "/path/to/extract")

* POST call with context

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

resp := client.MustPostWithContext(ctx, "https://domain.tld", "application/json", strings.NewReader("{}"))
defer resp.Body.Close()

Index

Constants

View Source
const (
	HttpContinueTimeout   = 5
	HttpKeepAlive         = 600
	HttpDialTimeout       = 10
	HttpOverallTimeout    = 15
	IdleTimeout           = 90
	MaxConnections        = 100
	ResponseHeaderTimeout = 10
	TLSDialTimeout        = 15
)

The Http connection and timeout configurations.

Variables

This section is empty.

Functions

func GetHttpClient

func GetHttpClient() *http.Client

GetHttpClient provides http client with configured connection and timeout.

func MustGetAndUntarWithContext added in v1.14.0

func MustGetAndUntarWithContext(ctx context.Context, url, target string)

MustGetAndUntarWithContext will make a http GET call to given URL and extract tar.gz content to target destination.

func MustGetAndUnzipWithContext added in v1.14.0

func MustGetAndUnzipWithContext(ctx context.Context, url, target string)

MustGetAndUnzipWithContext will make a http GET call to given URL and extract zip content to target destination.

func MustGetWithContext

func MustGetWithContext(ctx context.Context, url string) *http.Response

MustGetWithContext is a helper that wraps a http GET call to given URL and log any error.

func MustPostWithContext

func MustPostWithContext(ctx context.Context, url, contentType string, body *strings.Reader) *http.Response

MustPostWithContext is a helper that wraps a http POST call to given URL, content type, and body, as well as log any error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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