storage

package
v0.0.0-...-075c1f4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFileSize       = 20 * 1024 * 1024 // 20MB
	SignedURLDuration = 12 * time.Hour
	UploadURLDuration = time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileIdentifier

type FileIdentifier struct {
	BucketName string `validate:"required"`
	ObjectKey  string `validate:"required,min=4"`
}

type ImageService

type ImageService interface {
	Upload(ctx context.Context, req *ImageUploadRequest) (string, error)
	GetUploadURL(fileID FileIdentifier) (string, error)
	GetURL(fileID FileIdentifier) (string, error)
	GetURI(fileID FileIdentifier) string
	Delete(ctx context.Context, fileID FileIdentifier) error
	DeleteAllInvalid(ctx context.Context, bucketName string, validObjectKeys []string) error
}

func NewImageService

func NewImageService(
	validate *validator.Validate,
	storageRepo StorageRepository,
) ImageService

type ImageUploadRequest

type ImageUploadRequest struct {
	ImageData   []byte `validate:"required"`
	ContentType string `validate:"required,oneof=image/jpeg image/png image/jpg image/webp"`
	FileSize    int64  `validate:"required,min=1"`
	FileIdentifier
}

type StorageRepository

type StorageRepository interface {
	Upload(ctx context.Context, req *StorageUploadRequest) error
	Delete(ctx context.Context, fileID FileIdentifier) error
	GetUploadURL(fileID FileIdentifier, expiration time.Duration) (string, error)
	GetSignedURL(fileID FileIdentifier, expiration time.Duration) (string, error)
	GetAllObjectKeys(ctx context.Context, bucketName string) ([]string, error)
	Exists(ctx context.Context, fileID FileIdentifier) (bool, error)
	ToURI(fi FileIdentifier) string
	Close() error
}

func NewGCSStorageRepository

func NewGCSStorageRepository() (StorageRepository, error)

type StorageUploadRequest

type StorageUploadRequest struct {
	Data         []byte
	Reader       io.Reader
	ContentType  string
	CacheControl string
	FileIdentifier
}

Jump to

Keyboard shortcuts

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