storage

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 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 Driver

type Driver interface {
	Put(path string, content io.Reader) (string, error)
	Get(path string) (io.ReadCloser, error)
	Delete(path string) error
	URL(path string) string
}

Driver defines the interface for file storage backends.

func NewDriver

func NewDriver() (Driver, error)

NewDriver creates a storage driver based on the STORAGE_DRIVER env var. Supported values: "local" (default), "s3".

type LocalDriver

type LocalDriver struct {
	BasePath string // e.g. "storage/uploads"
	BaseURL  string // e.g. "/uploads"
}

LocalDriver stores files on the local filesystem.

func (*LocalDriver) Delete

func (d *LocalDriver) Delete(path string) error

Delete removes the file at the given path.

func (*LocalDriver) Get

func (d *LocalDriver) Get(path string) (io.ReadCloser, error)

Get opens the file at the given path and returns an io.ReadCloser.

func (*LocalDriver) Put

func (d *LocalDriver) Put(path string, content io.Reader) (string, error)

Put writes content to the given path under BasePath. Intermediate directories are created automatically.

func (*LocalDriver) URL

func (d *LocalDriver) URL(path string) string

URL returns the public URL for the given path.

type S3Driver

type S3Driver struct {
	Client   *s3.Client
	Bucket   string
	Region   string
	Endpoint string // optional custom endpoint for S3-compatible services
}

S3Driver stores files in an Amazon S3 (or compatible) bucket.

func NewS3Driver

func NewS3Driver() (*S3Driver, error)

NewS3Driver creates an S3Driver from environment variables.

Required env vars: S3_BUCKET, S3_REGION, S3_KEY, S3_SECRET. Optional: S3_ENDPOINT (for MinIO, DigitalOcean Spaces, etc.).

func (*S3Driver) Delete

func (d *S3Driver) Delete(path string) error

Delete removes an object from S3.

func (*S3Driver) Get

func (d *S3Driver) Get(path string) (io.ReadCloser, error)

Get retrieves an object from S3 and returns its body as io.ReadCloser.

func (*S3Driver) Put

func (d *S3Driver) Put(path string, content io.Reader) (string, error)

Put uploads content to the S3 bucket at the given key.

func (*S3Driver) URL

func (d *S3Driver) URL(path string) string

URL returns the public URL for the given S3 object.

Jump to

Keyboard shortcuts

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