httpclient

package
v0.0.0-...-eeb323e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTransport

func ContextWithTransport(ctx context.Context, transport http.RoundTripper) context.Context

ContextWithTransport returns a context with a http.RoundTripper for use as http.Client Transport

func TransportFromContext

func TransportFromContext(ctx context.Context) http.RoundTripper

TransportFromContext returns an http.RoundTripper for use as http.Client Transport from the context or nil

Types

type HTTPClient

type HTTPClient interface {
	// Get returns the body and media type of the URL using the provided context. The caller must close the body.
	//
	// This is optimized for easy content negotiation. Hence, the returned mediaType is stripped of qualifiers.
	// e.g. "Content-Type: application/json; charset=utf-8" will return mediaType "application/json"
	Get(ctx context.Context, url string, header http.Header) (body io.ReadCloser, mediaType string, err error)

	// GetJSON is a convenience function that calls json.Unmarshal after Get.
	GetJSON(ctx context.Context, url string, accept string, v interface{}) error
}

HTTPClient is a convenience wrapper for http.Client that consolidates common logic.

func New

func New(transport http.RoundTripper) HTTPClient

New returns a client that implicitly authenticates when it needs to Use ContextWithTransport when testing.

Jump to

Keyboard shortcuts

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