go-places/api/internal/blobstore/blobstore.go

30 lines
1.1 KiB
Go
Raw Permalink Normal View History

2026-10-07 15:14:50 +02:00
// Package blobstore stores the bytes of uploaded pictures. Keeping it behind an
// interface means the local filesystem can later be replaced by object storage
// without changing the upload handler.
package blobstore
import (
"context"
"errors"
"io"
)
var (
// ErrNotFound is returned when a key has no stored object.
ErrNotFound = errors.New("blob not found")
// ErrTooLarge is returned when the payload exceeds the configured limit.
ErrTooLarge = errors.New("blob exceeds maximum size")
)
// BlobStore saves and serves opaque byte payloads addressed by key.
type BlobStore interface {
// Put stores the contents of r under key and returns the number of bytes
// written. It must not read more than maxBytes from r.
Put(ctx context.Context, key string, r io.Reader, maxBytes int64) (int64, error)
// Get opens the object stored under key. The caller closes the reader.
Get(ctx context.Context, key string) (io.ReadCloser, error)
// Delete removes the object stored under key. Deleting a missing key is not
// an error.
Delete(ctx context.Context, key string) error
}