Documentation ¶
Index ¶
- Variables
- func AssertValid(verify types.Verification, data []byte) error
- func FetchResource(l *log.Logger, c *HttpClient, u url.URL) ([]byte, error)
- func FetchResourceAsReader(l *log.Logger, c *HttpClient, u url.URL) (io.ReadCloser, error)
- func GetHasher(verify types.Verification) (hash.Hash, error)
- type ErrHashMismatch
- type HttpClient
- func (c HttpClient) FetchConfig(url string, acceptedStatuses ...int) []byte
- func (c HttpClient) FetchConfigWithHeader(url string, header http.Header, acceptedStatuses ...int) []byte
- func (c HttpClient) Get(url string) ([]byte, int, error)
- func (c HttpClient) GetReader(url string) (io.ReadCloser, int, error)
- func (c HttpClient) GetReaderWithHeader(url string, header http.Header) (io.ReadCloser, int, error)
- func (c HttpClient) GetWithHeader(url string, header http.Header) ([]byte, int, error)
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 AssertValid ¶
func AssertValid(verify types.Verification, data []byte) error
func FetchResource ¶ added in v0.6.0
FetchResource fetches a resource given a URL. The supported schemes are http, data, and oem.
func FetchResourceAsReader ¶ added in v0.7.1
func FetchResourceAsReader(l *log.Logger, c *HttpClient, u url.URL) (io.ReadCloser, error)
FetchResourceAsReader returns a ReadCloser to the data at the url specified. The caller is responsible for closing the reader.
Types ¶
type ErrHashMismatch ¶
func (ErrHashMismatch) Error ¶
func (e ErrHashMismatch) Error() string
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.
func (HttpClient) FetchConfig ¶
func (c HttpClient) FetchConfig(url string, acceptedStatuses ...int) []byte
FetchConfig calls FetchConfigWithHeader with an empty set of headers.
func (HttpClient) FetchConfigWithHeader ¶ added in v0.5.0
func (c HttpClient) FetchConfigWithHeader(url string, header http.Header, acceptedStatuses ...int) []byte
FetchConfigWithHeader fetches a raw config from the provided URL and returns the response body on success or nil on failure. The caller must also provide a list of acceptable HTTP status codes and headers. If the response's status code is not in the provided list, it is considered a 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 (HttpClient) Get ¶
func (c HttpClient) Get(url string) ([]byte, int, error)
Get performs an HTTP GET on the provided URL and returns the response body, HTTP status code, and error (if any).
func (HttpClient) GetReader ¶ added in v0.7.1
func (c HttpClient) GetReader(url string) (io.ReadCloser, int, error)
GetReader performs an HTTP GET on the provided URL and returns the response body Reader, HTTP status code, and error (if any).
func (HttpClient) GetReaderWithHeader ¶ added in v0.7.1
func (c HttpClient) GetReaderWithHeader(url string, header http.Header) (io.ReadCloser, int, error)
GetReaderWithHeader performs an HTTP GET on the provided URL with the provided request header and returns the response body Reader, HTTP status code, and error (if any). By default, User-Agent and Accept are added to the header but these can be overridden.
func (HttpClient) GetWithHeader ¶
GetWithHeader performs an HTTP GET on the provided URL with the provided request header and returns the response body, HTTP status code, and error (if any). By default, User-Agent and Accept are added to the header but these can be overridden.