Documentation ¶
Index ¶
- type Client
- func (c *Client) ForceGet(r *Request) (io.ReadCloser, error)
- func (c *Client) ForceGetBytes(r *Request) ([]byte, error)
- func (c *Client) Get(u string) (io.ReadCloser, error)
- func (c *Client) GetAndStore(u, filepath string) (io.ReadCloser, error)
- func (c *Client) GetCached(r *Request) (io.ReadCloser, error)
- func (c *Client) GetCachedBytes(r *Request) ([]byte, error)
- func (c *Client) PrepCacheFile(r *Request) (string, error)
- type Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { BeforeRequest func(*http.Request) HTTPClient *http.Client CachePath string ThrottleMS int }
Client makes HTTP requests and caches the results
func NewClient ¶
NewClient initializes a default client for use in reading (and optionally caching) from remote servers. cachepath should be set to the directory where cached files' subdirectories reside.
func (*Client) ForceGet ¶
func (c *Client) ForceGet(r *Request) (io.ReadCloser, error)
ForceGet operates like GetCached except it overwrites a previously cached file if one exists
func (*Client) ForceGetBytes ¶
ForceGetBytes functions just like ForceGet, but automatically reads all bytes from the reader and returns them instead of just returning the reader
func (*Client) Get ¶
func (c *Client) Get(u string) (io.ReadCloser, error)
Get is the most basic function for a Client. No caching is done, and just the response body is returned. All external fetching eventually lands here.
func (*Client) GetAndStore ¶
func (c *Client) GetAndStore(u, filepath string) (io.ReadCloser, error)
GetAndStore downloads an external file and stores it at the given path
func (*Client) GetCached ¶
func (c *Client) GetCached(r *Request) (io.ReadCloser, error)
GetCached attempts to find a file for the given request, and fetches it from its source if the file isn't locally available
func (*Client) GetCachedBytes ¶
GetCachedBytes functions just like GetCached, but automatically reads all bytes from the reader and returns them instead of just returning the reader
type Request ¶
A Request contains everything needed both to look for the requested data on disk and fetch it and store it
func AutoRequest ¶
AutoRequest uses the URL to figure out filename and extension, but requires a sub-directory to avoid collisions since filename from URL can be overly simple, lacking in context, or just not very unique. Even so, we hash the URL to add a few "unique" characters to the filename.
func NewRequest ¶
NewRequest sets up a Request object for use in a Client's various cache-enabled functions. The filename and extension are often not a direct part of the URL, or else need to be more precise than a URL provides, so we require them to be specified here.