Documentation
¶
Index ¶
- Variables
- type BytesBuffer
- type BytesReader
- type FileService
- func (s *FileService) Delete(ctx context.Context, key string) error
- func (s *FileService) Download(ctx context.Context, key string) ([]byte, error)
- func (s *FileService) GetDownloadURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (s *FileService) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, error)
- type GCSConfig
- type GCSMockStorage
- func (m *GCSMockStorage) Delete(ctx context.Context, key string) error
- func (m *GCSMockStorage) Download(ctx context.Context, key string) ([]byte, error)
- func (m *GCSMockStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (m *GCSMockStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (m *GCSMockStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error
- type GCSStorage
- func (s *GCSStorage) Delete(ctx context.Context, key string) error
- func (s *GCSStorage) Download(ctx context.Context, key string) ([]byte, error)
- func (s *GCSStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (s *GCSStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *GCSStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error
- type MockStorage
- func (m *MockStorage) Delete(ctx context.Context, key string) error
- func (m *MockStorage) Download(ctx context.Context, key string) ([]byte, error)
- func (m *MockStorage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (m *MockStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (m *MockStorage) Upload(ctx context.Context, key string, data []byte, contentType string) error
- type ObjectStorage
- type S3Config
- type S3Storage
- func (s *S3Storage) Delete(ctx context.Context, key string) error
- func (s *S3Storage) Download(ctx context.Context, key string) ([]byte, error)
- func (s *S3Storage) GetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (s *S3Storage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *S3Storage) Upload(ctx context.Context, key string, data []byte, contentType string) error
- type UploadRequest
- type UploadResponse
Constants ¶
This section is empty.
Variables ¶
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
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
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) 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
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.
type MockStorage ¶
type MockStorage struct {
// contains filtered or unexported fields
}
MockStorage implements ObjectStorage for testing.
func NewMockStorage ¶
func NewMockStorage() *MockStorage
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 ¶
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).
type UploadRequest ¶
UploadRequest represents a file upload request.
func ParseMultipartForm ¶
func ParseMultipartForm(form *multipart.Form) ([]UploadRequest, error)
ParseMultipartForm parses a multipart form and extracts files.