Documentation
¶
Overview ¶
Package storage defines the object storage interface and provides implementations for local filesystem and S3-compatible object storage.
Index ¶
- Variables
- type Adapter
- type Local
- func (l *Local) AvailableSpace(ctx context.Context) (uint64, error)
- func (l *Local) Exists(ctx context.Context, endpoint, oid string) (bool, error)
- func (l *Local) Get(ctx context.Context, endpoint, oid string) (io.ReadCloser, int64, error)
- func (l *Local) Put(ctx context.Context, endpoint, oid string, reader io.Reader) error
- func (l *Local) Size(ctx context.Context, endpoint, oid string) (int64, error)
- type PresignedURLProvider
- type S3
- func (s *S3) AvailableSpace(_ context.Context) (uint64, error)
- func (s *S3) Exists(ctx context.Context, endpoint, oid string) (bool, error)
- func (s *S3) Get(ctx context.Context, endpoint, oid string) (io.ReadCloser, int64, error)
- func (s *S3) PresignGet(ctx context.Context, endpoint, oid string, expiry time.Duration) (string, error)
- func (s *S3) PresignPut(ctx context.Context, endpoint, oid string, expiry time.Duration) (string, error)
- func (s *S3) Put(ctx context.Context, endpoint, oid string, reader io.Reader) error
- func (s *S3) Size(ctx context.Context, endpoint, oid string) (int64, error)
- type S3Config
Constants ¶
This section is empty.
Variables ¶
var ErrHashMismatch = errors.New("hash mismatch")
ErrHashMismatch is returned when the computed SHA-256 hash of an uploaded object does not match the expected OID.
var ErrInsufficientStorage = errors.New("insufficient storage")
ErrInsufficientStorage is returned when the filesystem has no space left.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
Exists(ctx context.Context, endpoint, oid string) (bool, error)
Get(ctx context.Context, endpoint, oid string) (io.ReadCloser, int64, error)
Put(ctx context.Context, endpoint, oid string, reader io.Reader) error
Size(ctx context.Context, endpoint, oid string) (int64, error)
AvailableSpace(ctx context.Context) (uint64, error)
}
Adapter is the interface for object storage backends.
All methods accept a context.Context for cancellation. Implementations should check ctx.Err() before starting work. For streaming operations like Put, the context may not be monitored during I/O — callers should not rely on context cancellation to immediately abort an in-progress write. Network-backed implementations (e.g., S3) should propagate the context into their underlying client calls.
Put does not enforce a size limit on the reader. Callers are responsible for wrapping the reader with an appropriate limit (e.g., http.MaxBytesReader) before passing it to Put.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local stores objects on the local filesystem.
func (*Local) AvailableSpace ¶
AvailableSpace returns the number of bytes available for non-privileged users on the filesystem that contains the storage base path.
type PresignedURLProvider ¶
type PresignedURLProvider interface {
PresignGet(ctx context.Context, endpoint, oid string, expiry time.Duration) (href string, err error)
PresignPut(ctx context.Context, endpoint, oid string, expiry time.Duration) (href string, err error)
}
PresignedURLProvider is an optional interface that storage adapters can implement to provide presigned URLs for direct client-to-storage transfers. When an adapter implements this interface, the batch handler uses the presigned URLs instead of generating HMAC-signed proxy URLs. The local filesystem adapter does not implement this interface.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 stores objects in an S3-compatible bucket. It supports both AWS S3 and Cloudflare R2 through configurable endpoint and path style options.
func (*S3) AvailableSpace ¶
AvailableSpace returns math.MaxUint64 because S3 buckets have no practical storage limit.
func (*S3) PresignGet ¶
func (s *S3) PresignGet(ctx context.Context, endpoint, oid string, expiry time.Duration) (string, error)
PresignGet returns a presigned GET URL for direct client downloads.
func (*S3) PresignPut ¶
func (s *S3) PresignPut(ctx context.Context, endpoint, oid string, expiry time.Duration) (string, error)
PresignPut returns a presigned PUT URL for direct client uploads.