storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound = errors.New("file not found")
	ErrInvalidPath  = errors.New("invalid file path")
)

Functions

This section is empty.

Types

type BytesBuffer

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

BytesBuffer wraps a bytes.Buffer for testing.

func NewBytesBuffer

func NewBytesBuffer() *BytesBuffer

func (*BytesBuffer) Bytes

func (b *BytesBuffer) Bytes() []byte

func (*BytesBuffer) Write

func (b *BytesBuffer) Write(p []byte) (int, error)

type BytesReader

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

BytesReader wraps bytes as an io.Reader for testing.

func NewBytesReader

func NewBytesReader(data []byte) *BytesReader

func (*BytesReader) Read

func (r *BytesReader) Read(p []byte) (n int, err error)

type FileService

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

FileService handles file operations.

func NewFileService

func NewFileService(storage ObjectStorage, bucket, baseURL string, logger *slog.Logger) *FileService

NewFileService creates a new file service.

func (*FileService) Delete

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

Delete handles file deletion.

func (*FileService) Download

func (s *FileService) Download(ctx context.Context, key string) ([]byte, error)

Download handles file download.

func (*FileService) GetDownloadURL

func (s *FileService) GetDownloadURL(ctx context.Context, key string, expiry time.Duration) (string, error)

GetDownloadURL returns a signed download URL.

func (*FileService) Upload

func (s *FileService) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, error)

Upload handles file upload.

type GCSConfig

type GCSConfig struct {
	Bucket      string
	ProjectID   string
	Credentials string // Path to JSON credentials file
}

GCSConfig holds configuration for Google Cloud Storage.

type GCSMockStorage

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

GCSMockStorage provides a mock implementation for testing.

func NewGCSMockStorage

func NewGCSMockStorage() *GCSMockStorage

NewGCSMockStorage creates a mock GCS storage for testing.

func (*GCSMockStorage) Delete

func (m *GCSMockStorage) Delete(ctx context.Context, key string) error

func (*GCSMockStorage) Download

func (m *GCSMockStorage) Download(ctx context.Context, key string) ([]byte, error)

func (*GCSMockStorage) GetURL

func (m *GCSMockStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

func (*GCSMockStorage) List

func (m *GCSMockStorage) List(ctx context.Context, prefix string) ([]string, error)

func (*GCSMockStorage) Upload

func (m *GCSMockStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error

type GCSStorage

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

GCSStorage implements ObjectStorage using Google Cloud Storage.

func NewGCSStorage

func NewGCSStorage(ctx context.Context, cfg GCSConfig) (*GCSStorage, error)

NewGCSStorage creates a new GCS storage client.

func (*GCSStorage) Delete

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

Delete deletes a file from GCS.

func (*GCSStorage) Download

func (s *GCSStorage) Download(ctx context.Context, key string) ([]byte, error)

Download downloads a file from GCS.

func (*GCSStorage) GetURL

func (s *GCSStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

GetURL returns a signed URL for the file.

func (*GCSStorage) List

func (s *GCSStorage) List(ctx context.Context, prefix string) ([]string, error)

List lists files with the given prefix.

func (*GCSStorage) Upload

func (s *GCSStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error

Upload uploads a file to GCS.

type MockStorage

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

MockStorage implements ObjectStorage for testing.

func NewMockStorage

func NewMockStorage() *MockStorage

func (*MockStorage) Delete

func (m *MockStorage) Delete(ctx context.Context, key string) error

func (*MockStorage) Download

func (m *MockStorage) Download(ctx context.Context, key string) ([]byte, error)

func (*MockStorage) GetURL

func (m *MockStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

func (*MockStorage) List

func (m *MockStorage) List(ctx context.Context, prefix string) ([]string, error)

func (*MockStorage) Upload

func (m *MockStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error

type ObjectStorage

type ObjectStorage interface {
	// Upload uploads a file to the storage.
	Upload(ctx context.Context, key string, data []byte, contentType string) error

	// Download downloads a file from the storage.
	Download(ctx context.Context, key string) ([]byte, error)

	// Delete deletes a file from the storage.
	Delete(ctx context.Context, key string) error

	// GetURL returns a signed URL for the file.
	GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

	// List lists files with the given prefix.
	List(ctx context.Context, prefix string) ([]string, error)
}

ObjectStorage defines the interface for cloud object storage.

type S3Config

type S3Config struct {
	Bucket    string
	Region    string
	Endpoint  string
	AccessKey string
	SecretKey string
	UseSSL    bool
}

S3Config holds configuration for AWS S3.

type S3Storage

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

S3Storage implements ObjectStorage using AWS S3.

func NewS3Storage

func NewS3Storage(cfg S3Config) (*S3Storage, error)

NewS3Storage creates a new S3 storage client.

func NewS3StorageWithEndpoint

func NewS3StorageWithEndpoint(endpoint, region, bucket, accessKey, secretKey string) (*S3Storage, error)

NewS3StorageWithEndpoint creates S3 storage with custom endpoint (e.g., MinIO, DigitalOcean Spaces).

func (*S3Storage) Delete

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

Delete deletes a file from S3.

func (*S3Storage) Download

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

Download downloads a file from S3.

func (*S3Storage) GetURL

func (s *S3Storage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

GetURL returns a signed URL for the file.

func (*S3Storage) List

func (s *S3Storage) List(ctx context.Context, prefix string) ([]string, error)

List lists files with the given prefix.

func (*S3Storage) Upload

func (s *S3Storage) Upload(ctx context.Context, key string, data []byte, contentType string) error

Upload uploads a file to S3.

type UploadRequest

type UploadRequest struct {
	Filename    string
	ContentType string
	Data        []byte
}

UploadRequest represents a file upload request.

func ParseMultipartForm

func ParseMultipartForm(form *multipart.Form) ([]UploadRequest, error)

ParseMultipartForm parses a multipart form and extracts files.

type UploadResponse

type UploadResponse struct {
	Key        string
	URL        string
	Size       int64
	UploadedAt time.Time
}

UploadResponse represents the response from an upload.

Jump to

Keyboard shortcuts

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