resource

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	ErrTimeout = errors.New("unable to fetch resource in time")
)

Functions

func Fetch

func Fetch(l *log.Logger, c *HttpClient, u url.URL) ([]byte, error)

Fetch fetches a resource given a URL. The supported schemes are http, data, and oem.

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

func FetchConfig(l *log.Logger, c *HttpClient, u url.URL) []byte

FetchConfig fetches a raw config from the provided URL.

func FetchConfigWithHeader

func FetchConfigWithHeader(l *log.Logger, c *HttpClient, u url.URL, h http.Header) []byte

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, h http.Header, u url.URL) ([]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.

Jump to

Keyboard shortcuts

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