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 ¶
- type LocalStore
- func (s *LocalStore) Delete(_ context.Context, key string) error
- func (s *LocalStore) FileServer() http.Handler
- func (s *LocalStore) Open(_ context.Context, key string) (io.ReadCloser, error)
- func (s *LocalStore) Save(_ context.Context, key string, reader io.Reader) error
- func (s *LocalStore) URL(key string) string
- type S3Store
- type S3StoreConfig
- type Store
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 ¶
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 ¶
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.
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.