Documentation ¶
Index ¶
- Variables
- func Fetch(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL) ([]byte, error)
- func FetchAsReader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL) (io.ReadCloser, error)
- func FetchAsReaderWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) (io.ReadCloser, error)
- func FetchConfig(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL) ([]byte, error)
- func FetchConfigWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) ([]byte, error)
- func FetchWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) ([]byte, error)
- type HttpClient
Constants ¶
This section is empty.
Variables ¶
var ( ErrSchemeUnsupported = errors.New("unsupported source scheme") ErrPathNotAbsolute = errors.New("path is not absolute") ErrNotFound = errors.New("resource not found") ErrFailed = errors.New("failed to fetch resource") )
var (
ErrAttemptsExhausted = errors.New("unable to fetch resource (no more attempts available)")
)
Functions ¶
func FetchAsReader ¶
func FetchAsReader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL) (io.ReadCloser, error)
FetchAsReader returns a ReadCloser to the data at the URL specified. The caller is responsible for closing the reader.
func FetchAsReaderWithHeader ¶
func FetchAsReaderWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) (io.ReadCloser, error)
FetchAsReader returns a ReadCloser to the data at the URL specified. If the URL is of the http or https scheme, the provided header will be used when fetching. The caller is responsible for closing the reader.
func FetchConfig ¶
FetchConfig fetches a raw config from the provided URL.
func FetchConfigWithHeader ¶
func FetchConfigWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) ([]byte, error)
FetchConfigWithHeader fetches a raw config from the provided URL and returns the response body on success or nil on failure. The HTTP response must be OK, otherwise an empty (v.s. nil) config is returned. The provided headers are merged with a set of default headers.
func FetchWithHeader ¶
func FetchWithHeader(l *log.Logger, c *HttpClient, ctx context.Context, u url.URL, h http.Header) ([]byte, error)
FetchWithHeader fetches a resource given a URL. If the resource is of the http or https scheme, the provided header will be used when fetching. The supported schemes are http, data, and oem.
Types ¶
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient is a simple wrapper around the Go HTTP client that standardizes the process and logging of fetching payloads.
func NewHttpClient ¶
func NewHttpClient(logger *log.Logger) HttpClient
NewHttpClient creates a new client with the given logger.