Documentation
¶
Index ¶
- Constants
- Variables
- func IdentityOrder(order []int) bool
- func ReorderAdImages(store Store, adID int, order []int) error
- func ValidateReorderOrder(order []int, n int) error
- type ImageRef
- type LocalStore
- func (s *LocalStore) Copy(adID, fromIndex, toIndex int, suffix string) error
- func (s *LocalStore) Delete(adID, index int, suffix string) error
- func (s *LocalStore) DeleteAd(adID int) error
- func (s *LocalStore) DeleteUserAccount(userID int) error
- func (s *LocalStore) Get(adID, index int, suffix string) ([]byte, error)
- func (s *LocalStore) GetUserAccount(userID int) ([]byte, error)
- func (s *LocalStore) ListAd(adID int) ([]ImageRef, error)
- func (s *LocalStore) ModTime(adID, index int, suffix string) (time.Time, bool, error)
- func (s *LocalStore) PresignGet(adID, index int, suffix string, expiry time.Duration) (string, error)
- func (s *LocalStore) PresignGetUserAccount(userID int, expiry time.Duration) (string, error)
- func (s *LocalStore) PresignPut(adID, index int, suffix string, expiry time.Duration) (string, error)
- func (s *LocalStore) PresignPutUserAccount(userID int, expiry time.Duration) (string, error)
- func (s *LocalStore) Put(adID, index int, suffix string, data []byte) error
- func (s *LocalStore) PutUserAccount(userID int, data []byte) error
- func (s *LocalStore) Stat(adID, index int, suffix string) (bool, error)
- func (s *LocalStore) StatUserAccount(userID int) (bool, error)
- type MinioStore
- func (s *MinioStore) Copy(adID, fromIndex, toIndex int, suffix string) error
- func (s *MinioStore) Delete(adID, index int, suffix string) error
- func (s *MinioStore) DeleteAd(adID int) error
- func (s *MinioStore) DeleteUserAccount(userID int) error
- func (s *MinioStore) Get(adID, index int, suffix string) ([]byte, error)
- func (s *MinioStore) GetUserAccount(userID int) ([]byte, error)
- func (s *MinioStore) ListAd(adID int) ([]ImageRef, error)
- func (s *MinioStore) ModTime(adID, index int, suffix string) (time.Time, bool, error)
- func (s *MinioStore) PresignGet(adID, index int, suffix string, expiry time.Duration) (string, error)
- func (s *MinioStore) PresignGetUserAccount(userID int, expiry time.Duration) (string, error)
- func (s *MinioStore) PresignPut(adID, index int, suffix string, expiry time.Duration) (string, error)
- func (s *MinioStore) PresignPutUserAccount(userID int, expiry time.Duration) (string, error)
- func (s *MinioStore) Put(adID, index int, suffix string, data []byte) error
- func (s *MinioStore) PutUserAccount(userID int, data []byte) error
- func (s *MinioStore) Stat(adID, index int, suffix string) (bool, error)
- func (s *MinioStore) StatUserAccount(userID int) (bool, error)
- type Store
- type URLCache
- func (c *URLCache) InvalidateGetURL(adID, index int, suffix string)
- func (c *URLCache) InvalidateUserAccountURL(userID int)
- func (c *URLCache) ReusedGetURL(adID, index int, suffix string, expiry time.Duration) (string, error)
- func (c *URLCache) ReusedGetUserAccountURL(userID int, expiry time.Duration) (string, error)
Constants ¶
const ( ImageExt = "jpg" ImageMIME = "image/jpeg" )
Variables ¶
var ImageSizes = []string{"160w", "480w", "1200w"}
ImageSizes are the JPEG derivative suffixes stored per ad image.
Functions ¶
func IdentityOrder ¶ added in v0.0.23
IdentityOrder reports whether order is 1..n in ascending sequence.
func ReorderAdImages ¶ added in v0.0.23
ReorderAdImages remaps stored image files so position i holds former order[i-1]. Uses temporary high indexes to avoid overwrite collisions.
func ValidateReorderOrder ¶ added in v0.0.23
ValidateReorderOrder checks that order is a permutation of 1..n.
Types ¶
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
LocalStore writes ad images under baseDir/{adID}/{index}-{suffix}.jpg.
func NewLocal ¶
func NewLocal(baseDir string) *LocalStore
func (*LocalStore) Copy ¶ added in v0.0.23
func (s *LocalStore) Copy(adID, fromIndex, toIndex int, suffix string) error
func (*LocalStore) Delete ¶ added in v0.0.23
func (s *LocalStore) Delete(adID, index int, suffix string) error
func (*LocalStore) DeleteAd ¶
func (s *LocalStore) DeleteAd(adID int) error
func (*LocalStore) DeleteUserAccount ¶
func (s *LocalStore) DeleteUserAccount(userID int) error
func (*LocalStore) GetUserAccount ¶
func (s *LocalStore) GetUserAccount(userID int) ([]byte, error)
func (*LocalStore) PresignGet ¶
func (*LocalStore) PresignGetUserAccount ¶
func (*LocalStore) PresignPut ¶
func (*LocalStore) PresignPutUserAccount ¶
func (*LocalStore) Put ¶
func (s *LocalStore) Put(adID, index int, suffix string, data []byte) error
func (*LocalStore) PutUserAccount ¶
func (s *LocalStore) PutUserAccount(userID int, data []byte) error
func (*LocalStore) StatUserAccount ¶
func (s *LocalStore) StatUserAccount(userID int) (bool, error)
type MinioStore ¶
type MinioStore struct {
// contains filtered or unexported fields
}
MinioStore stores ad images in a MinIO bucket.
func NewMinio ¶
func NewMinio() (*MinioStore, error)
NewMinio connects to MinIO, ensures the bucket exists, and returns a store.
func (*MinioStore) Copy ¶ added in v0.0.23
func (s *MinioStore) Copy(adID, fromIndex, toIndex int, suffix string) error
func (*MinioStore) Delete ¶ added in v0.0.23
func (s *MinioStore) Delete(adID, index int, suffix string) error
func (*MinioStore) DeleteAd ¶
func (s *MinioStore) DeleteAd(adID int) error
func (*MinioStore) DeleteUserAccount ¶
func (s *MinioStore) DeleteUserAccount(userID int) error
func (*MinioStore) GetUserAccount ¶
func (s *MinioStore) GetUserAccount(userID int) ([]byte, error)
func (*MinioStore) PresignGet ¶
func (*MinioStore) PresignGetUserAccount ¶
func (*MinioStore) PresignPut ¶
func (*MinioStore) PresignPutUserAccount ¶
func (*MinioStore) Put ¶
func (s *MinioStore) Put(adID, index int, suffix string, data []byte) error
func (*MinioStore) PutUserAccount ¶
func (s *MinioStore) PutUserAccount(userID int, data []byte) error
func (*MinioStore) StatUserAccount ¶
func (s *MinioStore) StatUserAccount(userID int) (bool, error)
type Store ¶
type Store interface {
Put(adID, index int, suffix string, data []byte) error
Get(adID, index int, suffix string) ([]byte, error)
Stat(adID, index int, suffix string) (bool, error)
// ModTime is used to cache-bust stable proxy URLs after reorder/replace.
ModTime(adID, index int, suffix string) (time.Time, bool, error)
Copy(adID, fromIndex, toIndex int, suffix string) error
Delete(adID, index int, suffix string) error
ListAd(adID int) ([]ImageRef, error)
DeleteAd(adID int) error
PresignPut(adID, index int, suffix string,
expiry time.Duration) (string, error)
PresignGet(adID, index int, suffix string,
expiry time.Duration) (string, error)
PutUserAccount(userID int, data []byte) error
GetUserAccount(userID int) ([]byte, error)
StatUserAccount(userID int) (bool, error)
DeleteUserAccount(userID int) error
PresignPutUserAccount(userID int, expiry time.Duration) (string, error)
PresignGetUserAccount(userID int, expiry time.Duration) (string, error)
}
Store persists ad image files in MinIO. LocalStore exists for tests only.
func NewDefault ¶
NewDefault returns a MinIO-backed image store. MINIO_* env vars must be set.
type URLCache ¶
type URLCache struct {
// contains filtered or unexported fields
}
URLCache reuses PresignGet URLs for the signature lifetime (TTL = expiry).
func NewURLCache ¶
func (*URLCache) InvalidateGetURL ¶
InvalidateGetURL drops a cached GET URL.
func (*URLCache) InvalidateUserAccountURL ¶
InvalidateUserAccountURL drops a cached user account picture GET URL.