dal

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &http.Client{
	Timeout: 15 * time.Second,
}

DefaultClient is the default http client for Fetch. Similar to http.DefaultClient, but sets a timeout.

Functions

func Delete added in v0.13.0

func Delete(url string) ([]byte, error)

Delete is a convenience wrapper for Fetch.

func Fetch

func Fetch(fc *FetchConfig) ([]byte, error)

Fetch makes a request, caches its response, and returns the response body. By default, the cache is only used for GET requests. For all other methods, fc.CacheKey must be defined.

func Get added in v0.13.0

func Get(url string) ([]byte, error)

Get is a convenience wrapper for Fetch.

func Post added in v0.13.0

func Post(url, contentType string, body io.Reader) ([]byte, error)

Post is a convenience wrapper for Fetch.

func ResponseBody added in v0.15.0

func ResponseBody(resp *http.Response) ([]byte, error)

ResponseBody returns the response's body data, with support for gzipped responses.

func TTLFromResponse added in v0.15.0

func TTLFromResponse(r *http.Response) time.Duration

TTLFromResponse attempts to get a TTL value from a response's "cache-control" header, otherwise returning a default.

Types

type FetchConfig

type FetchConfig struct {
	*http.Request
	*http.Client
	// TTL is the time to live for a request's response in cache
	TTL time.Duration
	// CacheKey offers an optional key to use in place of the default key.
	// When defined, the response body of the request will be cached, no
	// matter the Method used.
	CacheKey string
	// Opt out of using the cache
	NoCache bool
}

FetchConfig holds all the information needed by dal.Fetch() to make a request.

func (*FetchConfig) Validate added in v0.15.0

func (fc *FetchConfig) Validate() error

Validate verifies that the given FetchConfig has the basic pieces of information supplied.

Jump to

Keyboard shortcuts

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