storage

package
v0.0.1-0...-104a2d1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOperationNotSupported = errors.New("operation not supported by this storage type")

Functions

This section is empty.

Types

type FSStore

type FSStore struct {
	BasePath string
}

FSStore implements the Store interface using the local filesystem.

func (*FSStore) BucketExists

func (fs *FSStore) BucketExists(ctx context.Context, bucket string) (bool, error)

func (*FSStore) CreatePublicBucket

func (fs *FSStore) CreatePublicBucket(ctx context.Context, bucket, region string) error

func (*FSStore) CreateSecureBucket

func (fs *FSStore) CreateSecureBucket(ctx context.Context, bucket, region string) error

func (*FSStore) Delete

func (fs *FSStore) Delete(ctx context.Context, bucket, key string) error

func (*FSStore) Download

func (fs *FSStore) Download(ctx context.Context, bucket, key string) (io.ReadCloser, error)

func (*FSStore) GenerateDeleteSignedURL

func (fs *FSStore) GenerateDeleteSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*FSStore) GenerateGetSignedURL

func (fs *FSStore) GenerateGetSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*FSStore) GeneratePutSignedURL

func (fs *FSStore) GeneratePutSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*FSStore) ListObjects

func (fs *FSStore) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)

func (*FSStore) Upload

func (fs *FSStore) Upload(ctx context.Context, bucket, key string, size int64, body io.Reader) error

type MinioStore

type MinioStore struct {
	Client *minio.Client
}

func (*MinioStore) BucketExists

func (s *MinioStore) BucketExists(ctx context.Context, bucket string) (bool, error)

func (*MinioStore) CreatePublicBucket

func (s *MinioStore) CreatePublicBucket(ctx context.Context, bucket, region string) error

func (*MinioStore) CreateSecureBucket

func (s *MinioStore) CreateSecureBucket(ctx context.Context, bucket, region string) error

func (*MinioStore) Delete

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

func (*MinioStore) Download

func (s *MinioStore) Download(ctx context.Context, bucket, key string) (io.ReadCloser, error)

func (*MinioStore) GenerateDeleteSignedURL

func (s *MinioStore) GenerateDeleteSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

TODO: Fix this

func (*MinioStore) GenerateGetSignedURL

func (s *MinioStore) GenerateGetSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*MinioStore) GeneratePutSignedURL

func (s *MinioStore) GeneratePutSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*MinioStore) ListObjects

func (s *MinioStore) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)

func (*MinioStore) Upload

func (s *MinioStore) Upload(ctx context.Context, bucket, key string, size int64, body io.Reader) error

type S3Store

type S3Store struct {
	Client        *s3.Client
	PresignClient *s3.PresignClient
	// contains filtered or unexported fields
}

S3Store implements the Store interface using the AWS S3 SDK.

func (*S3Store) BucketExists

func (s *S3Store) BucketExists(ctx context.Context, bucket string) (bool, error)

func (*S3Store) CreatePublicBucket

func (s *S3Store) CreatePublicBucket(ctx context.Context, bucket, region string) error

func (*S3Store) CreateSecureBucket

func (s *S3Store) CreateSecureBucket(ctx context.Context, bucket, region string) error

func (*S3Store) Delete

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

func (*S3Store) Download

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

func (*S3Store) GenerateDeleteSignedURL

func (s *S3Store) GenerateDeleteSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*S3Store) GenerateGetSignedURL

func (s *S3Store) GenerateGetSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*S3Store) GeneratePutSignedURL

func (s *S3Store) GeneratePutSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)

func (*S3Store) ListObjects

func (s *S3Store) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)

func (*S3Store) Upload

func (s *S3Store) Upload(ctx context.Context, bucket, key string, size int64, body io.Reader) error

type Storage

type Storage interface {
	// Upload uploads data from the reader to the specified bucket and key.
	Upload(ctx context.Context, bucket, key string, size int64, body io.Reader) error
	// Download retrieves the object from the specified bucket and key.
	// The caller is responsible for closing the returned io.ReadCloser.
	Download(ctx context.Context, bucket, key string) (io.ReadCloser, error)
	// Delete removes the object from the specified bucket and key.
	Delete(ctx context.Context, bucket, key string) error
	// ListObjects lists objects in the specified bucket with the given prefix.
	ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)
	// GenerateGetSignedURL creates a presigned URL for getting an object.
	GenerateGetSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)
	// GeneratePutSignedURL creates a presigned URL for putting an object.
	GeneratePutSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)
	// GenerateDeleteSignedURL creates a presigned URL for deleting an object.
	GenerateDeleteSignedURL(ctx context.Context, bucket, key string, expires time.Duration) (string, error)
	// BucketExists checks if a bucket exists.
	BucketExists(ctx context.Context, bucket string) (bool, error)
	// CreatePublicBucket creates a bucket (semantics depend on implementation, S3 won't make it world-readable by default).
	CreatePublicBucket(ctx context.Context, bucket, region string) error
	// CreateSecureBucket creates a bucket with stricter security settings (e.g., encryption, access blocks for S3).
	CreateSecureBucket(ctx context.Context, bucket, region string) error
}

Store defines the interface for interacting with different storage backends.

func NewFS

func NewFS(path string) (Storage, error)

NewFS creates a new Store implementation using the local filesystem. The path provided will be the root directory under which buckets are created as subdirectories.

func NewMinio

func NewMinio(ctx context.Context, endpoint, region, accessKey, secretKey string, useSSL bool) (Storage, error)

NewMinio creates a new Store implementation for MinIO (S3 compatible).

func NewR2

func NewR2(ctx context.Context, accountID, accessKey, secretKey string) (Storage, error)

NewR2 creates a new Store implementation for Cloudflare R2.

func NewS3

func NewS3(ctx context.Context, region, accessKey, secretKey string) (Storage, error)

NewS3 creates a new Store implementation for AWS S3.

func NewStorageProvider

func NewStorageProvider(cfg config.Storage, logger *zerolog.Logger) (Storage, error)

Jump to

Keyboard shortcuts

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