Documentation
¶
Overview ¶
Package imagecache fetches remote images (covers) once and keeps them on disk, so browsers never fetch from metadata or source sites themselves: that would leak users' addresses and referrers, and many sites refuse hotlinking anyway.
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) Get(ctx context.Context, rawURL string) (Image, error)
- func (c *Cache) GetFresh(ctx context.Context, key string, maxAge time.Duration, fetch Fetcher) (Image, error)
- func (c *Cache) GetWith(ctx context.Context, key string, fetch Fetcher) (Image, error)
- func (c *Cache) SetHTTPClient(hc *http.Client)
- type Fetcher
- type Image
- type Signer
Constants ¶
const MaxBytes = 15 << 20
MaxBytes caps one image.
Variables ¶
var ErrNotImage = errors.New("imagecache: not an image")
ErrNotImage is a response that isn't an image.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a directory of fetched images, keyed by a hash of their URL. It is rebuildable: deleting the directory only costs refetches.
func (*Cache) GetFresh ¶
func (c *Cache) GetFresh(ctx context.Context, key string, maxAge time.Duration, fetch Fetcher) (Image, error)
GetFresh is GetWith for images that may change: one cached longer than maxAge (0: forever) is fetched again, and kept when that fails.
func (*Cache) GetWith ¶
GetWith returns the image cached under key, calling fetch on first use. Concurrent requests for the same key share one fetch.
func (*Cache) SetHTTPClient ¶
SetHTTPClient replaces the HTTP client (tests).
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer signs image references the server hands out (e.g. a source's cover reference), so the image endpoint only fetches what the server itself listed, never an arbitrary URL a caller makes up.
func LoadSigner ¶
LoadSigner reads the instance's signing key, creating it on first use.