Documentation ¶
Index ¶
- Variables
- func Fetch(l *log.Logger, c *HttpClient, u url.URL) ([]byte, error)
- func FetchAsReader(l *log.Logger, c *HttpClient, u url.URL) (io.ReadCloser, error)
- func FetchAsReaderWithHeader(l *log.Logger, c *HttpClient, h http.Header, u url.URL) (io.ReadCloser, error)
- func FetchConfig(l *log.Logger, c *HttpClient, u url.URL) []byte
- func FetchConfigWithHeader(l *log.Logger, c *HttpClient, u url.URL, h http.Header) []byte
- func FetchWithHeader(l *log.Logger, c *HttpClient, h http.Header, u url.URL) ([]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 (
ErrTimeout = errors.New("unable to fetch resource in time")
)
Functions ¶
func FetchAsReader ¶
func FetchAsReader(l *log.Logger, c *HttpClient, 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, h http.Header, u url.URL) (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 ¶
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 ¶
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.