imagestore

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 16 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

View Source
const (
	ImageExt  = "jpg"
	ImageMIME = "image/jpeg"
)

Variables

View Source
var ImageSizes = []string{"160w", "480w", "1200w"}

ImageSizes are the JPEG derivative suffixes stored per ad image.

Functions

func IdentityOrder added in v0.0.23

func IdentityOrder(order []int) bool

IdentityOrder reports whether order is 1..n in ascending sequence.

func ReorderAdImages added in v0.0.23

func ReorderAdImages(store Store, adID int, order []int) error

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

func ValidateReorderOrder(order []int, n int) error

ValidateReorderOrder checks that order is a permutation of 1..n.

Types

type ImageRef

type ImageRef struct {
	Index  int
	Suffix string
}

ImageRef identifies one stored ad image variant.

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) Get

func (s *LocalStore) Get(adID, index int, suffix string) ([]byte, error)

func (*LocalStore) GetUserAccount

func (s *LocalStore) GetUserAccount(userID int) ([]byte, error)

func (*LocalStore) ListAd

func (s *LocalStore) ListAd(adID int) ([]ImageRef, error)

func (*LocalStore) ModTime added in v0.0.23

func (s *LocalStore) ModTime(adID, index int, suffix string) (time.Time, bool, error)

func (*LocalStore) PresignGet

func (s *LocalStore) PresignGet(adID, index int, suffix string,
	expiry time.Duration) (string, error)

func (*LocalStore) PresignGetUserAccount

func (s *LocalStore) PresignGetUserAccount(userID int,
	expiry time.Duration) (string, error)

func (*LocalStore) PresignPut

func (s *LocalStore) PresignPut(adID, index int, suffix string,
	expiry time.Duration) (string, error)

func (*LocalStore) PresignPutUserAccount

func (s *LocalStore) PresignPutUserAccount(userID int,
	expiry time.Duration) (string, error)

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) Stat

func (s *LocalStore) Stat(adID, index int, suffix string) (bool, 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) Get

func (s *MinioStore) Get(adID, index int, suffix string) ([]byte, error)

func (*MinioStore) GetUserAccount

func (s *MinioStore) GetUserAccount(userID int) ([]byte, error)

func (*MinioStore) ListAd

func (s *MinioStore) ListAd(adID int) ([]ImageRef, error)

func (*MinioStore) ModTime added in v0.0.23

func (s *MinioStore) ModTime(adID, index int, suffix string) (time.Time, bool, error)

func (*MinioStore) PresignGet

func (s *MinioStore) PresignGet(adID, index int, suffix string,
	expiry time.Duration) (string, error)

func (*MinioStore) PresignGetUserAccount

func (s *MinioStore) PresignGetUserAccount(userID int,
	expiry time.Duration) (string, error)

func (*MinioStore) PresignPut

func (s *MinioStore) PresignPut(adID, index int, suffix string,
	expiry time.Duration) (string, error)

func (*MinioStore) PresignPutUserAccount

func (s *MinioStore) PresignPutUserAccount(userID int,
	expiry time.Duration) (string, error)

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) Stat

func (s *MinioStore) Stat(adID, index int, suffix string) (bool, 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

func NewDefault() (Store, error)

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 NewURLCache(store Store) (*URLCache, error)

func (*URLCache) InvalidateGetURL

func (c *URLCache) InvalidateGetURL(adID, index int, suffix string)

InvalidateGetURL drops a cached GET URL.

func (*URLCache) InvalidateUserAccountURL

func (c *URLCache) InvalidateUserAccountURL(userID int)

InvalidateUserAccountURL drops a cached user account picture GET URL.

func (*URLCache) ReusedGetURL

func (c *URLCache) ReusedGetURL(adID, index int, suffix string,
	expiry time.Duration) (string, error)

ReusedGetURL returns a stable PresignGet URL. Miss (or TTL expiry) mints fresh.

func (*URLCache) ReusedGetUserAccountURL

func (c *URLCache) ReusedGetUserAccountURL(userID int,
	expiry time.Duration) (string, error)

ReusedGetUserAccountURL returns a stable PresignGet for a user account picture.

Jump to

Keyboard shortcuts

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