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
- func GetHttpClient() *http.Client
- func MustGetAndUntarWithContext(ctx context.Context, url, target string)
- func MustGetAndUnzipWithContext(ctx context.Context, url, target string)
- func MustGetWithContext(ctx context.Context, url string) *http.Response
- func MustPostWithContext(ctx context.Context, url, contentType string, body *strings.Reader) *http.Response
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 ¶
GetHttpClient provides http client with configured connection and timeout.
func MustGetAndUntarWithContext ¶ added in v1.14.0
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
MustGetAndUnzipWithContext will make a http GET call to given URL and extract zip content to target destination.
func MustGetWithContext ¶
MustGetWithContext is a helper that wraps a http GET call to given URL and log any error.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.