Documentation
¶
Overview ¶
Package storage provides an abstraction for object storage operations.
Index ¶
- Variables
- type FileStorage
- func (f *FileStorage) Delete(ctx context.Context, key string) error
- func (f *FileStorage) Exists(ctx context.Context, key string) (bool, error)
- func (f *FileStorage) Get(ctx context.Context, key string) ([]byte, string, error)
- func (f *FileStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (f *FileStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (f *FileStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (f *FileStorage) Put(ctx context.Context, key string, data []byte) error
- func (f *FileStorage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
- func (f *FileStorage) PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
- type GCSStorage
- func (g *GCSStorage) Delete(ctx context.Context, key string) error
- func (g *GCSStorage) Exists(ctx context.Context, key string) (bool, error)
- func (g *GCSStorage) Get(ctx context.Context, key string) ([]byte, string, error)
- func (g *GCSStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (g *GCSStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (g *GCSStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (g *GCSStorage) Put(ctx context.Context, key string, data []byte) error
- func (g *GCSStorage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
- func (g *GCSStorage) PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
- type MockStorage
- func (m *MockStorage) Cleanup() error
- func (m *MockStorage) Delete(ctx context.Context, key string) error
- func (m *MockStorage) Exists(ctx context.Context, key string) (bool, error)
- func (m *MockStorage) Get(ctx context.Context, key string) ([]byte, string, error)
- func (m *MockStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (m *MockStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (m *MockStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (m *MockStorage) Put(ctx context.Context, key string, data []byte) error
- func (m *MockStorage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
- func (m *MockStorage) PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
- type ObjectMetadata
- type S3Storage
- func (s *S3Storage) Delete(ctx context.Context, key string) error
- func (s *S3Storage) Exists(ctx context.Context, key string) (bool, error)
- func (s *S3Storage) Get(ctx context.Context, key string) ([]byte, string, error)
- func (s *S3Storage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (s *S3Storage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *S3Storage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *S3Storage) Put(ctx context.Context, key string, data []byte) error
- func (s *S3Storage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
- func (s *S3Storage) PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
- type ScopedStorage
- func (s *ScopedStorage) Delete(ctx context.Context, key string) error
- func (s *ScopedStorage) Exists(ctx context.Context, key string) (bool, error)
- func (s *ScopedStorage) Get(ctx context.Context, key string) ([]byte, string, error)
- func (s *ScopedStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (s *ScopedStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *ScopedStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *ScopedStorage) Prefix() string
- func (s *ScopedStorage) Put(ctx context.Context, key string, data []byte) error
- func (s *ScopedStorage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
- func (s *ScopedStorage) PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
- type Storage
- type StorageOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = s3lect.ErrStorageNotFound ErrPrecondition = s3lect.ErrStoragePrecondition )
Common storage errors - use s3lect's errors for compatibility
Functions ¶
This section is empty.
Types ¶
type FileStorage ¶
type FileStorage struct {
// contains filtered or unexported fields
}
FileStorage implements Storage interface for local filesystem operations
func NewFileStorage ¶
func NewFileStorage(baseDir string) (*FileStorage, error)
NewFileStorage creates a new file-based storage
func (*FileStorage) Delete ¶
func (f *FileStorage) Delete(ctx context.Context, key string) error
Delete removes a file
func (*FileStorage) GetMetadata ¶
func (f *FileStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
GetMetadata retrieves file metadata
func (*FileStorage) GetStream ¶
func (f *FileStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
GetStream retrieves a file as a stream
func (*FileStorage) PutIfMatch ¶
PutIfMatch stores data only if ETag matches (optimistic locking) Empty etag means file must not exist
type GCSStorage ¶
type GCSStorage struct {
// contains filtered or unexported fields
}
GCSStorage implements Storage interface using Google Cloud Storage
func NewGCSStorage ¶
func NewGCSStorage(client *storage.Client, bucket string) *GCSStorage
NewGCSStorage creates a new GCS storage instance
func (*GCSStorage) Delete ¶
func (g *GCSStorage) Delete(ctx context.Context, key string) error
Delete removes an object from GCS
func (*GCSStorage) Get ¶
Get retrieves an object from GCS and returns its contents and ETag (Generation)
func (*GCSStorage) GetMetadata ¶
func (g *GCSStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
GetMetadata retrieves metadata for an object
func (*GCSStorage) GetStream ¶
func (g *GCSStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
GetStream retrieves an object as a stream
func (*GCSStorage) PutIfMatch ¶
PutIfMatch stores an object only if the generation matches (optimistic locking) Empty etag means object must not exist
type MockStorage ¶
type MockStorage struct {
// contains filtered or unexported fields
}
MockStorage implements Storage interface using local filesystem for testing
func NewMock ¶
func NewMock() *MockStorage
NewMock creates a new mock storage instance with a temporary directory
func NewMockStorage ¶
func NewMockStorage(baseDir string) (*MockStorage, error)
NewMockStorage creates a new mock storage instance
func (*MockStorage) Cleanup ¶
func (m *MockStorage) Cleanup() error
Cleanup removes all files in the mock storage (useful for testing)
func (*MockStorage) Delete ¶
func (m *MockStorage) Delete(ctx context.Context, key string) error
Delete removes an object from mock storage
func (*MockStorage) Get ¶
Get retrieves an object from mock storage and returns its contents and ETag
func (*MockStorage) GetMetadata ¶
func (m *MockStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
GetMetadata retrieves metadata for an object
func (*MockStorage) GetStream ¶
func (m *MockStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
GetStream retrieves an object as a stream
func (*MockStorage) PutIfMatch ¶
PutIfMatch stores an object only if the ETag matches (optimistic locking) Empty etag means object must not exist
type ObjectMetadata ¶
type ObjectMetadata struct {
Key string
Size int64
LastModified time.Time
ETag string
ContentType string
}
ObjectMetadata contains metadata about a stored object
type S3Storage ¶
type S3Storage struct {
// contains filtered or unexported fields
}
S3Storage implements Storage interface using AWS S3
func NewS3Storage ¶
NewS3Storage creates a new S3 storage instance
func (*S3Storage) GetMetadata ¶
GetMetadata retrieves metadata for an object
func (*S3Storage) PutIfMatch ¶
PutIfMatch stores an object only if the ETag matches (optimistic locking) Empty etag means object must not exist
type ScopedStorage ¶
type ScopedStorage struct {
// contains filtered or unexported fields
}
ScopedStorage wraps a Storage interface and prefixes all keys with a given prefix. This enables logical separation of cluster-scoped and shard-scoped data within a single bucket.
func (*ScopedStorage) Delete ¶
func (s *ScopedStorage) Delete(ctx context.Context, key string) error
Delete removes an object from storage
func (*ScopedStorage) Get ¶
Get retrieves an object from storage and returns its contents and its etag
func (*ScopedStorage) GetMetadata ¶
func (s *ScopedStorage) GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
GetMetadata retrieves metadata for an object, updating the Key field to strip the prefix
func (*ScopedStorage) GetStream ¶
func (s *ScopedStorage) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
GetStream retrieves an object as a stream
func (*ScopedStorage) List ¶
List lists objects with the given prefix, stripping the scope prefix from returned keys
func (*ScopedStorage) Prefix ¶
func (s *ScopedStorage) Prefix() string
Prefix returns the configured prefix for this scoped storage
func (*ScopedStorage) PutIfMatch ¶
PutIfMatch stores an object only if the ETag matches (empty string = must not exist)
type Storage ¶
type Storage interface {
// Get retrieves an object from storage and returns its contents and its etag
// Returns ErrNotFound if object does not exist
Get(ctx context.Context, key string) ([]byte, string, error)
// Put stores an object in storage
Put(ctx context.Context, key string, data []byte) error
// PutIfMatch stores an object only if the ETag matches (empty string = must not exist)
// Returns ErrPrecondition if ETag doesn't match
PutIfMatch(ctx context.Context, key string, data []byte, etag string) error
// Delete removes an object from storage
Delete(ctx context.Context, key string) error
// Exists checks if an object exists in storage
Exists(ctx context.Context, key string) (bool, error)
// List lists objects with the given prefix
List(ctx context.Context, prefix string) ([]string, error)
// GetMetadata retrieves metadata for an object
GetMetadata(ctx context.Context, key string) (*ObjectMetadata, error)
// GetStream retrieves an object as a stream
GetStream(ctx context.Context, key string) (io.ReadCloser, error)
// PutStream stores an object from a stream
PutStream(ctx context.Context, key string, reader io.Reader, size int64) error
}
Storage provides an abstraction for object storage operations
func New ¶
func New(ctx context.Context, logger *slog.Logger, provider, bucket string) (Storage, func(), error)
New creates the appropriate storage backend based on the provider string. Valid providers: "s3", "gcs", "file" Returns the storage, a cleanup function, and any error.
func NewScopedStorage ¶
NewScopedStorage creates a new ScopedStorage that prefixes all keys. The prefix should include a trailing slash if keys should be nested (e.g., "cluster/").
func NewWithOptions ¶
func NewWithOptions(ctx context.Context, logger *slog.Logger, opts StorageOptions) (Storage, func(), error)
NewWithOptions creates a storage backend with full configuration options. This supports custom endpoints for S3-compatible backends like SeaweedFS, MinIO, and Ceph RGW.
type StorageOptions ¶
type StorageOptions struct {
Provider string // Storage provider: "s3", "gcs", "file"
Bucket string // Bucket name (or path for file storage)
Region string // AWS region override (optional)
Endpoint string // Custom endpoint for S3-compatible backends (SeaweedFS, MinIO, Ceph RGW)
PathStyle bool // Use path-style access for S3 (default: false, uses virtual-hosted style)
}
StorageOptions contains parameters for creating storage backends with full configuration.