Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertToAVIF(data []byte) ([]byte, error)
- func ConvertToWebP(data []byte) ([]byte, error)
- func DetectDeviceType(r *http.Request) string
- func GetDeviceTypeFromUserAgent(userAgent string) string
- func GetFromS3(ctx context.Context, key string) ([]byte, error)
- func GetRandomImage(basePath string, deviceType DeviceType, avifSupport bool) (string, error)
- func InitCleaner()
- func InitMetadataStore() error
- func InitS3Client() error
- func InitStorage() error
- func IsImageFile(filename string) bool
- func ReadSeeker(r io.Reader) (io.ReadSeeker, error)
- func SetConfig(cfg *config.Config)
- func String(v string) *string
- func TriggerCleanup()
- func UploadToS3(ctx context.Context, key string, data []byte) error
- type ByteReadSeeker
- type DeviceType
- type ImageCleaner
- type ImageFormatInfo
- type ImageMetadata
- type LocalMetadataStore
- func (lms *LocalMetadataStore) DeleteMetadata(ctx context.Context, id string) error
- func (lms *LocalMetadataStore) GetMetadata(ctx context.Context, id string) (*ImageMetadata, error)
- func (lms *LocalMetadataStore) ListExpiredImages(ctx context.Context) ([]*ImageMetadata, error)
- func (lms *LocalMetadataStore) SaveMetadata(ctx context.Context, metadata *ImageMetadata) error
- type LocalStorage
- type MetadataStore
- type S3MetadataStore
- func (sms *S3MetadataStore) DeleteMetadata(ctx context.Context, id string) error
- func (sms *S3MetadataStore) GetMetadata(ctx context.Context, id string) (*ImageMetadata, error)
- func (sms *S3MetadataStore) ListExpiredImages(ctx context.Context) ([]*ImageMetadata, error)
- func (sms *S3MetadataStore) SaveMetadata(ctx context.Context, metadata *ImageMetadata) error
- type S3Object
- type S3Storage
- func (s *S3Storage) Delete(ctx context.Context, key string) error
- func (s *S3Storage) Get(ctx context.Context, key string) ([]byte, error)
- func (s *S3Storage) ListObjects(ctx context.Context, prefix string) ([]S3Object, error)
- func (s *S3Storage) Store(ctx context.Context, key string, data []byte) error
- type StorageConfig
- type StorageProvider
Constants ¶
const ( DeviceMobile = "mobile" DeviceDesktop = "desktop" )
String constants for device types
Variables ¶
var Config *config.Config
Global configuration instance
var ErrInvalidOffset = errors.New("invalid offset")
var S3Client *s3.Client
var SupportedImageExtensions = []string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".avif"}
SupportedImageExtensions contains all file extensions recognized by the application
Functions ¶
func ConvertToAVIF ¶
ConvertToAVIF converts image data to AVIF format
func ConvertToWebP ¶
ConvertToWebP converts image data to WebP format
func DetectDeviceType ¶
DetectDeviceType returns a string identifier ("mobile" or "desktop") based on User-Agent
func GetDeviceTypeFromUserAgent ¶
GetDeviceTypeFromUserAgent extracts device type from a User-Agent string
func GetRandomImage ¶
func GetRandomImage(basePath string, deviceType DeviceType, avifSupport bool) (string, error)
GetRandomImage returns a path to a random image with appropriate format for device and browser
DEPRECATED: This function is deprecated and will be removed in a future version. Use handlers.RandomImage, handlers.RandomImageHandler, or handlers.LocalRandomImageHandler instead, which offer better PNG support and more consistent behavior across storage types.
func InitMetadataStore ¶
func InitMetadataStore() error
InitMetadataStore initializes the metadata storage
func InitS3Client ¶
func InitS3Client() error
func IsImageFile ¶
IsImageFile checks if a filename has a supported image extension
func ReadSeeker ¶
func ReadSeeker(r io.Reader) (io.ReadSeeker, error)
ReadSeeker converts an io.Reader to an io.ReadSeeker by reading all content into memory
Types ¶
type ByteReadSeeker ¶
type ByteReadSeeker struct {
// contains filtered or unexported fields
}
ByteReadSeeker implements io.ReadSeeker for a byte slice
func NewByteReadSeeker ¶
func NewByteReadSeeker(data []byte) *ByteReadSeeker
type DeviceType ¶
type DeviceType int
const ( Desktop DeviceType = iota Mobile )
func DetectDevice ¶
func DetectDevice(r *http.Request) DeviceType
DetectDevice returns the DeviceType enum (Mobile or Desktop) based on User-Agent
type ImageCleaner ¶
type ImageCleaner struct {
// contains filtered or unexported fields
}
ImageCleaner is responsible for cleaning up expired images
var Cleaner *ImageCleaner
Global cleaner instance
func NewImageCleaner ¶
func NewImageCleaner() *ImageCleaner
NewImageCleaner creates a new image cleaner
type ImageFormatInfo ¶
type ImageFormatInfo struct {
Format string // Format name (e.g., "jpeg", "png", "gif")
Extension string // File extension (e.g., ".jpg", ".png", ".gif")
MimeType string // MIME type (e.g., "image/jpeg", "image/png", "image/gif")
}
ImageFormatInfo contains information about an image's format
func DetectImageFormat ¶
func DetectImageFormat(data []byte) (ImageFormatInfo, error)
DetectImageFormat detects the format of an image from its binary data
type ImageMetadata ¶
type ImageMetadata struct {
ID string `json:"id"` // Image ID (without extension)
OriginalName string `json:"originalName"` // Original filename
UploadTime time.Time `json:"uploadTime"` // Upload timestamp
ExpiryTime time.Time `json:"expiryTime"` // Expiry timestamp (if set)
Format string `json:"format"` // Original format
Orientation string `json:"orientation"` // Image orientation
Tags []string `json:"tags"` // Image tags for categorization
Paths struct {
Original string `json:"original"` // Path to original image
WebP string `json:"webp"` // Path to WebP format
AVIF string `json:"avif"` // Path to AVIF format
} `json:"paths"`
}
ImageMetadata stores metadata information for images
type LocalMetadataStore ¶
type LocalMetadataStore struct {
BasePath string
}
LocalMetadataStore implements metadata storage for local filesystem
func NewLocalMetadataStore ¶
func NewLocalMetadataStore(basePath string) (*LocalMetadataStore, error)
NewLocalMetadataStore creates a new local metadata store
func (*LocalMetadataStore) DeleteMetadata ¶
func (lms *LocalMetadataStore) DeleteMetadata(ctx context.Context, id string) error
DeleteMetadata deletes image metadata
func (*LocalMetadataStore) GetMetadata ¶
func (lms *LocalMetadataStore) GetMetadata(ctx context.Context, id string) (*ImageMetadata, error)
GetMetadata retrieves image metadata from a local file
func (*LocalMetadataStore) ListExpiredImages ¶
func (lms *LocalMetadataStore) ListExpiredImages(ctx context.Context) ([]*ImageMetadata, error)
ListExpiredImages lists all expired images
func (*LocalMetadataStore) SaveMetadata ¶
func (lms *LocalMetadataStore) SaveMetadata(ctx context.Context, metadata *ImageMetadata) error
SaveMetadata saves image metadata to a local file
type LocalStorage ¶
type LocalStorage struct {
BasePath string
}
LocalStorage implements StorageProvider for local filesystem
func NewLocalStorage ¶
func NewLocalStorage(basePath string) (*LocalStorage, error)
type MetadataStore ¶
type MetadataStore interface {
SaveMetadata(ctx context.Context, metadata *ImageMetadata) error
GetMetadata(ctx context.Context, id string) (*ImageMetadata, error)
ListExpiredImages(ctx context.Context) ([]*ImageMetadata, error)
DeleteMetadata(ctx context.Context, id string) error
}
MetadataStore defines the interface for metadata storage operations
var MetadataManager MetadataStore
Global metadata storage instance
type S3MetadataStore ¶
type S3MetadataStore struct {
// contains filtered or unexported fields
}
S3MetadataStore implements metadata storage for S3
func NewS3MetadataStore ¶
func NewS3MetadataStore(s3Storage *S3Storage) *S3MetadataStore
NewS3MetadataStore creates a new S3 metadata store
func (*S3MetadataStore) DeleteMetadata ¶
func (sms *S3MetadataStore) DeleteMetadata(ctx context.Context, id string) error
DeleteMetadata deletes image metadata from S3
func (*S3MetadataStore) GetMetadata ¶
func (sms *S3MetadataStore) GetMetadata(ctx context.Context, id string) (*ImageMetadata, error)
GetMetadata retrieves image metadata from S3
func (*S3MetadataStore) ListExpiredImages ¶
func (sms *S3MetadataStore) ListExpiredImages(ctx context.Context) ([]*ImageMetadata, error)
ListExpiredImages lists all expired images in S3
func (*S3MetadataStore) SaveMetadata ¶
func (sms *S3MetadataStore) SaveMetadata(ctx context.Context, metadata *ImageMetadata) error
SaveMetadata saves image metadata to S3
type S3Storage ¶
type S3Storage struct {
// contains filtered or unexported fields
}
S3Storage implements StorageProvider for S3-compatible storage
func NewS3Storage ¶
func (*S3Storage) ListObjects ¶
ListObjects lists objects in S3 with the given prefix
type StorageConfig ¶
type StorageConfig struct {
Type string // "local" or "s3"
LocalPath string // base path for local storage
}
StorageConfig represents the storage configuration
type StorageProvider ¶
type StorageProvider interface {
Store(ctx context.Context, key string, data []byte) error
Get(ctx context.Context, key string) ([]byte, error)
Delete(ctx context.Context, key string) error
}
StorageProvider defines the interface for storage operations
var Storage StorageProvider
Global storage instance
func NewStorageProvider ¶
func NewStorageProvider(cfg StorageConfig) (StorageProvider, error)
NewStorageProvider creates a new storage provider based on configuration