38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package storage
|
|
|
|
//go:generate mockgen -source=storage.go -destination=mock/mock_storage.go -package=mock
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// FileInfo represents metadata about a stored file
|
|
type FileInfo struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Size int64 `json:"size"`
|
|
ContentType string `json:"content_type"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
// Storage defines the interface for file storage operations
|
|
type Storage interface {
|
|
// Save stores a file and returns its FileInfo
|
|
Save(ctx context.Context, name string, contentType string, reader io.Reader) (*FileInfo, error)
|
|
|
|
// Get retrieves a file by its ID
|
|
Get(ctx context.Context, id string) (io.ReadCloser, *FileInfo, error)
|
|
|
|
// Delete removes a file by its ID
|
|
Delete(ctx context.Context, id string) error
|
|
|
|
// List returns a list of files with optional prefix
|
|
List(ctx context.Context, prefix string, limit int, offset int) ([]*FileInfo, error)
|
|
|
|
// Exists checks if a file exists
|
|
Exists(ctx context.Context, id string) (bool, error)
|
|
}
|