storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package storage provides file storage backends for generated applications. It defines the Store interface and provides LocalStore (filesystem) and S3Store (AWS S3) implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalStore

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

LocalStore stores files on the local filesystem.

func NewLocalStore

func NewLocalStore(baseDir, urlPrefix string) *LocalStore

NewLocalStore creates a new LocalStore that saves files under baseDir and generates URLs with the given prefix.

func (*LocalStore) Delete

func (s *LocalStore) Delete(_ context.Context, key string) error

Delete removes the file at baseDir/key. If key is a URL returned by URL(), the prefix is stripped automatically.

func (*LocalStore) FileServer

func (s *LocalStore) FileServer() http.Handler

FileServer returns an http.Handler that serves files from baseDir. Directory listings are disabled — only individual files are served.

func (*LocalStore) Open

func (s *LocalStore) Open(_ context.Context, key string) (io.ReadCloser, error)

Open returns a ReadCloser for the file at baseDir/key.

func (*LocalStore) Save

func (s *LocalStore) Save(_ context.Context, key string, reader io.Reader) error

Save writes the contents of reader to baseDir/key, creating parent directories. The key is sanitized to prevent path traversal outside baseDir.

func (*LocalStore) URL

func (s *LocalStore) URL(key string) string

URL returns the public URL for the given key.

type S3Store

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

S3Store stores files in AWS S3.

func NewS3Store

func NewS3Store(cfg S3StoreConfig) (*S3Store, error)

NewS3Store creates a new S3Store.

func (*S3Store) Delete

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

Delete removes the object at the given key from S3. Also accepts URLs returned by URL() — the known prefix is stripped. S3 DeleteObject is idempotent — deleting a non-existent key returns success.

func (*S3Store) Open

func (s *S3Store) Open(ctx context.Context, key string) (io.ReadCloser, error)

Open returns a ReadCloser for the object at the given key in S3.

func (*S3Store) Save

func (s *S3Store) Save(ctx context.Context, key string, reader io.Reader) error

Save uploads the contents of reader to the given key in S3. ContentType is inferred from the key's file extension.

func (*S3Store) URL

func (s *S3Store) URL(key string) string

URL returns the public URL for the given key. Uses CDNPrefix if configured, otherwise constructs the standard S3 URL.

type S3StoreConfig

type S3StoreConfig struct {
	Bucket          string
	Region          string
	AccessKeyID     string
	SecretAccessKey string
	Endpoint        string // Custom endpoint for MinIO/LocalStack
	CDNPrefix       string // Optional CDN URL prefix (e.g., "https://cdn.example.com")
}

S3StoreConfig configures an S3-backed file store.

type Store

type Store interface {
	Save(ctx context.Context, key string, reader io.Reader) error
	Open(ctx context.Context, key string) (io.ReadCloser, error)
	Delete(ctx context.Context, key string) error
	URL(key string) string
}

Store is the interface for file storage backends. Keys are opaque storage paths (e.g., "galleries/id/photo.jpg"). Delete also accepts URLs returned by URL() — implementations strip their known prefix to recover the underlying key.

Jump to

Keyboard shortcuts

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