imagestore

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 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

This section is empty.

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

func (s *MinioStore) DeleteAd(adID int) error

func (*MinioStore) DeleteKey

func (s *MinioStore) DeleteKey(key string) error

DeleteKey removes a raw bucket key.

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

func (s *MinioStore) KeyExists(key string) (bool, error)

KeyExists reports whether a raw bucket key is present.

func (*MinioStore) ListAd

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

func (*MinioStore) ListKeys

func (s *MinioStore) ListKeys() ([]string, error)

ListKeys returns every object key in the bucket.

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

func (s *MinioStore) ReadKey(key string) ([]byte, error)

ReadKey returns the object body for a raw bucket key.

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)

func (*MinioStore) WriteJPEG

func (s *MinioStore) WriteJPEG(key string, data []byte) error

WriteJPEG writes JPEG bytes to a raw bucket key.

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