storage

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Backend: "local" or "s3"
	Backend string

	// Local settings
	LocalBaseDir       string // filesystem base dir, e.g. ./uploads
	LocalPublicBaseURL string // public base URL/prefix served by the API, e.g. /uploads

	// S3 settings (also compatible with MinIO)
	S3Endpoint        string // optional; if empty uses AWS SDK endpoint resolution or MinIO endpoint
	S3Region          string
	S3Bucket          string
	S3AccessKeyID     string
	S3SecretAccessKey string
	S3UseSSL          bool
	S3ForcePathStyle  bool
	S3PublicBaseURL   string // optional CDN/CloudFront domain; if set, used to construct public URL
}

Config is a generic storage configuration. Concrete backends may use a subset.

type LocalStorage

type LocalStorage struct {
	// contains filtered or unexported fields
}

func NewLocalStorage

func NewLocalStorage(baseDir, publicBaseURL string) *LocalStorage

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, key string) error

func (*LocalStorage) Save

func (s *LocalStorage) Save(ctx context.Context, key string, r io.Reader, size int64, contentType string) (string, error)

type S3Storage

type S3Storage struct {
	// contains filtered or unexported fields
}

func NewS3Storage

func NewS3Storage(cfg Config) (*S3Storage, error)

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, key string) error

func (*S3Storage) Save

func (s *S3Storage) Save(ctx context.Context, key string, r io.Reader, size int64, contentType string) (string, error)

type Storage

type Storage interface {
	// Save stores content at the provided key (e.g., "profile/filename.jpg") and returns a public URL.
	Save(ctx context.Context, key string, r io.Reader, size int64, contentType string) (publicURL string, err error)
	// Delete removes an object at key. Should be idempotent.
	Delete(ctx context.Context, key string) error
}

Storage abstracts upload/delete operations and returns a public URL for saved objects. Implementations must be safe for concurrent use.

Jump to

Keyboard shortcuts

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