storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectMIME

func DetectMIME(content []byte) string

DetectMIME detects the MIME type of a byte slice.

Types

type LocalStorage

type LocalStorage struct {
	// contains filtered or unexported fields
}

LocalStorage implements the Storage interface for the local filesystem.

func NewLocalStorage

func NewLocalStorage(rootDir string) *LocalStorage

NewLocalStorage creates a new LocalStorage.

func (*LocalStorage) Copy

func (s *LocalStorage) Copy(ctx context.Context, src, dest string) error

Copy copies a file on the local filesystem.

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, path string) error

Delete removes a file from the local filesystem.

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a file exists on the local filesystem.

func (*LocalStorage) Get

func (s *LocalStorage) Get(ctx context.Context, path string) ([]byte, error)

Get reads a file from the local filesystem.

func (*LocalStorage) Move

func (s *LocalStorage) Move(ctx context.Context, src, dest string) error

Move moves a file on the local filesystem.

func (*LocalStorage) Put

func (s *LocalStorage) Put(ctx context.Context, path string, content []byte) error

Put writes a file to the local filesystem.

func (*LocalStorage) SignedURL

func (s *LocalStorage) SignedURL(ctx context.Context, path string, expiresIn time.Duration) (string, error)

SignedURL returns a relative URL for the file (local storage doesn't presign).

func (*LocalStorage) URL

func (s *LocalStorage) URL(path string) (string, error)

URL returns a relative URL for the file.

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

MemoryStorage implements the Storage interface in-memory for test_util.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new MemoryStorage.

func (*MemoryStorage) Copy

func (s *MemoryStorage) Copy(ctx context.Context, src, dest string) error

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(ctx context.Context, path string) error

func (*MemoryStorage) Exists

func (s *MemoryStorage) Exists(ctx context.Context, path string) (bool, error)

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(ctx context.Context, path string) ([]byte, error)

func (*MemoryStorage) Move

func (s *MemoryStorage) Move(ctx context.Context, src, dest string) error

func (*MemoryStorage) Put

func (s *MemoryStorage) Put(ctx context.Context, path string, content []byte) error

func (*MemoryStorage) SignedURL

func (s *MemoryStorage) SignedURL(ctx context.Context, path string, expiresIn time.Duration) (string, error)

func (*MemoryStorage) URL

func (s *MemoryStorage) URL(path string) (string, error)

type S3Storage

type S3Storage struct {
	// contains filtered or unexported fields
}

S3Storage implements the Storage interface for S3-compatible APIs.

func NewS3Storage

func NewS3Storage(ctx context.Context, cfg config.StorageConfig) (*S3Storage, error)

NewS3Storage creates a new S3Storage.

func (*S3Storage) Copy

func (s *S3Storage) Copy(ctx context.Context, src, dest string) error

Copy copies an object within S3.

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, path string) error

Delete removes a file from S3.

func (*S3Storage) Exists

func (s *S3Storage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if an object exists in S3.

func (*S3Storage) Get

func (s *S3Storage) Get(ctx context.Context, path string) ([]byte, error)

Get reads a file from S3.

func (*S3Storage) Move

func (s *S3Storage) Move(ctx context.Context, src, dest string) error

Move moves an object within S3.

func (*S3Storage) Put

func (s *S3Storage) Put(ctx context.Context, path string, content []byte) error

Put writes a file to S3.

func (*S3Storage) SignedURL

func (s *S3Storage) SignedURL(ctx context.Context, path string, expiresIn time.Duration) (string, error)

SignedURL returns a presigned URL for the file. IMPORTANT: This method does not perform authorization. Any application-level endpoint calling this MUST verify the user has access to the requested path.

func (*S3Storage) URL

func (s *S3Storage) URL(path string) (string, error)

URL returns the public URL for the file.

type Storage

type Storage interface {
	Put(ctx context.Context, path string, content []byte) error
	Get(ctx context.Context, path string) ([]byte, error)
	Delete(ctx context.Context, path string) error
	URL(path string) (string, error)
	SignedURL(ctx context.Context, path string, expiresIn time.Duration) (string, error)
	Exists(ctx context.Context, path string) (bool, error)
	Copy(ctx context.Context, src, dest string) error
	Move(ctx context.Context, src, dest string) error
}

Storage defines the interface for file storage.

Jump to

Keyboard shortcuts

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