resource

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2017 License: Apache-2.0 Imports: 21 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, 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, u url.URL) ([]byte, error)

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, 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 FetchFromTftp added in v0.15.0

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

FetchFromTftp fetches a resource from a tftp server.

func FetchWithHeader

func FetchWithHeader(l *log.Logger, c *HttpClient, 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, tftp, 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, timeouts types.Timeouts) HttpClient

NewHttpClient creates a new client with the given logger and timeouts.

Jump to

Keyboard shortcuts

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