resource

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2016 License: Apache-2.0 Imports: 18 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 (
	ErrAttemptsExhausted = errors.New("unable to fetch resource (no more attempts available)")
)

Functions

func Fetch

func Fetch(l *log.Logger, c *HttpClient, ctx context.Context, 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, 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

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

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.

Jump to

Keyboard shortcuts

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