Documentation
¶
Index ¶
- Variables
- func Delete(url string) ([]byte, error)
- func Fetch(fc *FetchConfig) ([]byte, error)
- func Get(url string) ([]byte, error)
- func Post(url, contentType string, body io.Reader) ([]byte, error)
- func ResponseBody(resp *http.Response) ([]byte, error)
- func TTLFromResponse(r *http.Response) time.Duration
- type FetchConfig
Constants ¶
This section is empty.
Variables ¶
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 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 ResponseBody ¶ added in v0.15.0
ResponseBody returns the response's body data, with support for gzipped responses.
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.