Documentation
ΒΆ
Overview ΒΆ
Package storage provides unified object storage with support for multiple backends including local filesystem, S3, GCS, and Azure Blob Storage.
Index ΒΆ
- Variables
- func IsValidSize(size int64, maxSize int64) bool
- func NewExtension(config Config) forge.Extension
- func ValidateMetadata(metadata map[string]string) error
- type BackendConfig
- type BackendHealth
- type BufferPool
- type BytesBufferPool
- type CircuitBreaker
- func (cb *CircuitBreaker) CanAttempt() bool
- func (cb *CircuitBreaker) Execute(ctx context.Context, name string, fn func() error) error
- func (cb *CircuitBreaker) GetState() CircuitState
- func (cb *CircuitBreaker) RecordFailure()
- func (cb *CircuitBreaker) RecordSuccess()
- func (cb *CircuitBreaker) Reset()
- type CircuitState
- type Config
- type EnhancedLocalBackend
- func (b *EnhancedLocalBackend) Copy(ctx context.Context, srcKey, dstKey string) error
- func (b *EnhancedLocalBackend) Delete(ctx context.Context, key string) error
- func (b *EnhancedLocalBackend) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *EnhancedLocalBackend) Exists(ctx context.Context, key string) (bool, error)
- func (b *EnhancedLocalBackend) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
- func (b *EnhancedLocalBackend) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (b *EnhancedLocalBackend) Move(ctx context.Context, srcKey, dstKey string) error
- func (b *EnhancedLocalBackend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *EnhancedLocalBackend) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *EnhancedLocalBackend) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
- type EnhancedLocalConfig
- type Extension
- func (e *Extension) Dependencies() []string
- func (e *Extension) Description() string
- func (e *Extension) Health(ctx context.Context) error
- func (e *Extension) Name() string
- func (e *Extension) Register(app forge.App) error
- func (e *Extension) Start(ctx context.Context) error
- func (e *Extension) Stop(ctx context.Context) error
- func (e *Extension) Version() string
- type HealthCheckConfig
- type HealthChecker
- type ListOption
- type ListOptions
- type LocalBackend
- func (b *LocalBackend) Copy(ctx context.Context, srcKey, dstKey string) error
- func (b *LocalBackend) Delete(ctx context.Context, key string) error
- func (b *LocalBackend) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *LocalBackend) Exists(ctx context.Context, key string) (bool, error)
- func (b *LocalBackend) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
- func (b *LocalBackend) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (b *LocalBackend) Move(ctx context.Context, srcKey, dstKey string) error
- func (b *LocalBackend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *LocalBackend) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *LocalBackend) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
- type Object
- type ObjectMetadata
- type OverallHealth
- type PathValidator
- type RateLimiter
- type ResilienceConfig
- type ResilientStorage
- func (rs *ResilientStorage) Copy(ctx context.Context, srcKey, dstKey string) error
- func (rs *ResilientStorage) Delete(ctx context.Context, key string) error
- func (rs *ResilientStorage) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (rs *ResilientStorage) Exists(ctx context.Context, key string) (bool, error)
- func (rs *ResilientStorage) GetCircuitBreakerState() CircuitState
- func (rs *ResilientStorage) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
- func (rs *ResilientStorage) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (rs *ResilientStorage) Move(ctx context.Context, srcKey, dstKey string) error
- func (rs *ResilientStorage) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (rs *ResilientStorage) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (rs *ResilientStorage) ResetCircuitBreaker()
- func (rs *ResilientStorage) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
- type S3Backend
- func (b *S3Backend) Copy(ctx context.Context, srcKey, dstKey string) error
- func (b *S3Backend) Delete(ctx context.Context, key string) error
- func (b *S3Backend) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *S3Backend) Exists(ctx context.Context, key string) (bool, error)
- func (b *S3Backend) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
- func (b *S3Backend) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (b *S3Backend) Move(ctx context.Context, srcKey, dstKey string) error
- func (b *S3Backend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *S3Backend) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *S3Backend) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
- type S3Config
- type Storage
- type StorageManager
- func (m *StorageManager) Backend(name string) Storage
- func (m *StorageManager) BackendHealth(ctx context.Context, name string) (*BackendHealth, error)
- func (m *StorageManager) Copy(ctx context.Context, srcKey, dstKey string) error
- func (m *StorageManager) Delete(ctx context.Context, key string) error
- func (m *StorageManager) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (m *StorageManager) Exists(ctx context.Context, key string) (bool, error)
- func (m *StorageManager) GetURL(ctx context.Context, key string) string
- func (m *StorageManager) Health(ctx context.Context) error
- func (m *StorageManager) HealthDetailed(ctx context.Context, checkAll bool) (*OverallHealth, error)
- func (m *StorageManager) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
- func (m *StorageManager) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
- func (m *StorageManager) Move(ctx context.Context, srcKey, dstKey string) error
- func (m *StorageManager) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (m *StorageManager) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (m *StorageManager) Start(ctx context.Context) error
- func (m *StorageManager) Stop(ctx context.Context) error
- func (m *StorageManager) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
- type UploadOption
- type UploadOptions
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( // Configuration errors ErrNoBackendsConfigured = errors.New("no storage backends configured") ErrNoDefaultBackend = errors.New("no default backend specified") ErrDefaultBackendNotFound = errors.New("default backend not found in configuration") ErrInvalidBackendType = errors.New("invalid backend type") ErrBackendNotFound = errors.New("backend not found") // Operation errors ErrObjectNotFound = errors.New("object not found") ErrObjectAlreadyExists = errors.New("object already exists") ErrInvalidKey = errors.New("invalid object key") ErrUploadFailed = errors.New("upload failed") ErrDownloadFailed = errors.New("download failed") ErrDeleteFailed = errors.New("delete failed") ErrPresignNotSupported = errors.New("presigned URLs not supported for this backend") ErrMultipartNotSupported = errors.New("multipart upload not supported for this backend") // Resilience errors ErrCircuitBreakerOpen = errors.New("circuit breaker is open") ErrRateLimitExceeded = errors.New("rate limit exceeded") // Validation errors ErrFileTooLarge = errors.New("file size exceeds maximum allowed size") ErrInvalidContentType = errors.New("invalid content type") ErrInvalidPath = errors.New("invalid path: potential path traversal detected") )
Functions ΒΆ
func IsValidSize ΒΆ
IsValidSize checks if a file size is within limits
func NewExtension ΒΆ
NewExtension creates a new storage extension
func ValidateMetadata ΒΆ
ValidateMetadata validates metadata keys and values
Types ΒΆ
type BackendConfig ΒΆ
type BackendConfig struct {
Type string `yaml:"type" json:"type"` // local, s3, gcs, azure
Config map[string]interface{} `yaml:"config" json:"config"`
}
BackendConfig is the configuration for a storage backend
type BackendHealth ΒΆ
type BackendHealth struct {
Name string `json:"name"`
Healthy bool `json:"healthy"`
ResponseTime time.Duration `json:"response_time"`
Error string `json:"error,omitempty"`
LastChecked time.Time `json:"last_checked"`
CheckType string `json:"check_type"`
}
BackendHealth represents health status of a backend
type BufferPool ΒΆ
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool manages a pool of reusable buffers for efficient I/O operations
func NewBufferPool ΒΆ
func NewBufferPool(bufferSize int) *BufferPool
NewBufferPool creates a new buffer pool with the specified buffer size
type BytesBufferPool ΒΆ
type BytesBufferPool struct {
// contains filtered or unexported fields
}
BytesBufferPool manages a pool of bytes.Buffer for efficient operations
func NewBytesBufferPool ΒΆ
func NewBytesBufferPool() *BytesBufferPool
NewBytesBufferPool creates a new bytes buffer pool
func (*BytesBufferPool) Get ΒΆ
func (bbp *BytesBufferPool) Get() *bytes.Buffer
Get retrieves a buffer from the pool
func (*BytesBufferPool) Put ΒΆ
func (bbp *BytesBufferPool) Put(buf *bytes.Buffer)
Put returns a buffer to the pool
type CircuitBreaker ΒΆ
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements circuit breaker pattern
func NewCircuitBreaker ΒΆ
func NewCircuitBreaker(config ResilienceConfig, logger forge.Logger, metrics forge.Metrics) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) CanAttempt ΒΆ
func (cb *CircuitBreaker) CanAttempt() bool
CanAttempt checks if a request can be attempted
func (*CircuitBreaker) GetState ΒΆ
func (cb *CircuitBreaker) GetState() CircuitState
GetState returns current circuit state
func (*CircuitBreaker) RecordFailure ΒΆ
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed execution
func (*CircuitBreaker) RecordSuccess ΒΆ
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful execution
type CircuitState ΒΆ
type CircuitState int
CircuitState represents circuit breaker state
const ( CircuitClosed CircuitState = iota CircuitOpen CircuitHalfOpen )
func (CircuitState) String ΒΆ
func (s CircuitState) String() string
type Config ΒΆ
type Config struct {
// Default backend name
Default string `yaml:"default" json:"default" default:"local"`
// Backend configurations
Backends map[string]BackendConfig `yaml:"backends" json:"backends"`
// Features
EnablePresignedURLs bool `yaml:"enable_presigned_urls" json:"enable_presigned_urls" default:"true"`
PresignExpiry time.Duration `yaml:"presign_expiry" json:"presign_expiry" default:"15m"`
MaxUploadSize int64 `yaml:"max_upload_size" json:"max_upload_size" default:"5368709120"` // 5GB
ChunkSize int `yaml:"chunk_size" json:"chunk_size" default:"5242880"` // 5MB
// CDN
EnableCDN bool `yaml:"enable_cdn" json:"enable_cdn" default:"false"`
CDNBaseURL string `yaml:"cdn_base_url" json:"cdn_base_url"`
// Resilience configuration
Resilience ResilienceConfig `yaml:"resilience" json:"resilience"`
// Use enhanced backend (with locking, pooling, etc.)
UseEnhancedBackend bool `yaml:"use_enhanced_backend" json:"use_enhanced_backend" default:"true"`
}
Config is the storage extension configuration
func DefaultConfig ΒΆ
func DefaultConfig() Config
DefaultConfig returns the default storage configuration
type EnhancedLocalBackend ΒΆ
type EnhancedLocalBackend struct {
// contains filtered or unexported fields
}
EnhancedLocalBackend implements enhanced local filesystem storage with proper locking and pooling
func NewEnhancedLocalBackend ΒΆ
func NewEnhancedLocalBackend(config map[string]interface{}, logger forge.Logger, metrics forge.Metrics) (*EnhancedLocalBackend, error)
NewEnhancedLocalBackend creates a new enhanced local filesystem backend
func (*EnhancedLocalBackend) Copy ΒΆ
func (b *EnhancedLocalBackend) Copy(ctx context.Context, srcKey, dstKey string) error
Copy copies a file with proper locking
func (*EnhancedLocalBackend) Delete ΒΆ
func (b *EnhancedLocalBackend) Delete(ctx context.Context, key string) error
Delete deletes a file with proper locking
func (*EnhancedLocalBackend) Download ΒΆ
func (b *EnhancedLocalBackend) Download(ctx context.Context, key string) (io.ReadCloser, error)
Download downloads a file with proper locking
func (*EnhancedLocalBackend) List ΒΆ
func (b *EnhancedLocalBackend) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
List lists files with a prefix
func (*EnhancedLocalBackend) Metadata ΒΆ
func (b *EnhancedLocalBackend) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
Metadata retrieves object metadata
func (*EnhancedLocalBackend) Move ΒΆ
func (b *EnhancedLocalBackend) Move(ctx context.Context, srcKey, dstKey string) error
Move moves a file with proper locking
func (*EnhancedLocalBackend) PresignDownload ΒΆ
func (b *EnhancedLocalBackend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignDownload generates a presigned URL for download
func (*EnhancedLocalBackend) PresignUpload ΒΆ
func (b *EnhancedLocalBackend) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignUpload generates a presigned URL for upload
func (*EnhancedLocalBackend) Upload ΒΆ
func (b *EnhancedLocalBackend) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
Upload uploads a file with proper locking and validation
type EnhancedLocalConfig ΒΆ
type EnhancedLocalConfig struct {
RootDir string
BaseURL string
Secret string
ChunkSize int64
MaxUploadSize int64
}
EnhancedLocalConfig contains configuration for enhanced local backend
type Extension ΒΆ
type Extension struct {
// contains filtered or unexported fields
}
Extension implements the storage extension
func (*Extension) Dependencies ΒΆ
Dependencies returns the list of extension dependencies
func (*Extension) Description ΒΆ
Description returns the extension description
type HealthCheckConfig ΒΆ
type HealthCheckConfig struct {
Timeout time.Duration `yaml:"timeout" json:"timeout" default:"5s"`
WriteTestFile bool `yaml:"write_test_file" json:"write_test_file" default:"true"`
TestKey string `yaml:"test_key" json:"test_key" default:".health_check"`
CheckAll bool `yaml:"check_all" json:"check_all" default:"false"`
EnableMetrics bool `yaml:"enable_metrics" json:"enable_metrics" default:"true"`
}
HealthCheckConfig configures health check behavior
func DefaultHealthCheckConfig ΒΆ
func DefaultHealthCheckConfig() HealthCheckConfig
DefaultHealthCheckConfig returns default health check configuration
type HealthChecker ΒΆ
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker performs comprehensive health checks on storage backends
func NewHealthChecker ΒΆ
func NewHealthChecker(backends map[string]Storage, logger forge.Logger, metrics forge.Metrics, config HealthCheckConfig) *HealthChecker
NewHealthChecker creates a new health checker
func (*HealthChecker) CheckHealth ΒΆ
func (hc *HealthChecker) CheckHealth(ctx context.Context, defaultBackend string, checkAll bool) (*OverallHealth, error)
CheckHealth performs health check on default backend or all backends
func (*HealthChecker) GetBackendHealth ΒΆ
func (hc *HealthChecker) GetBackendHealth(ctx context.Context, name string) (*BackendHealth, error)
GetBackendHealth gets health status of a specific backend
type ListOption ΒΆ
type ListOption func(*ListOptions)
ListOption is a functional option for listing
func WithRecursive ΒΆ
func WithRecursive(recursive bool) ListOption
WithRecursive sets recursive listing
type ListOptions ΒΆ
ListOptions contains list options
type LocalBackend ΒΆ
type LocalBackend struct {
// contains filtered or unexported fields
}
LocalBackend implements storage using local filesystem
func NewLocalBackend ΒΆ
func NewLocalBackend(config map[string]interface{}, logger forge.Logger, metrics forge.Metrics) (*LocalBackend, error)
NewLocalBackend creates a new local filesystem backend
func (*LocalBackend) Copy ΒΆ
func (b *LocalBackend) Copy(ctx context.Context, srcKey, dstKey string) error
Copy copies a file
func (*LocalBackend) Delete ΒΆ
func (b *LocalBackend) Delete(ctx context.Context, key string) error
Delete deletes a file
func (*LocalBackend) Download ΒΆ
func (b *LocalBackend) Download(ctx context.Context, key string) (io.ReadCloser, error)
Download downloads a file
func (*LocalBackend) List ΒΆ
func (b *LocalBackend) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
List lists files with a prefix
func (*LocalBackend) Metadata ΒΆ
func (b *LocalBackend) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
Metadata retrieves object metadata
func (*LocalBackend) Move ΒΆ
func (b *LocalBackend) Move(ctx context.Context, srcKey, dstKey string) error
Move moves a file
func (*LocalBackend) PresignDownload ΒΆ
func (b *LocalBackend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignDownload generates a presigned URL for download
func (*LocalBackend) PresignUpload ΒΆ
func (b *LocalBackend) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignUpload generates a presigned URL for upload
func (*LocalBackend) Upload ΒΆ
func (b *LocalBackend) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
Upload uploads a file
type Object ΒΆ
type Object struct {
Key string `json:"key"`
Size int64 `json:"size"`
LastModified time.Time `json:"last_modified"`
ETag string `json:"etag"`
ContentType string `json:"content_type"`
Metadata map[string]string `json:"metadata"`
}
Object represents a storage object
type ObjectMetadata ΒΆ
type ObjectMetadata struct {
Key string `json:"key"`
Size int64 `json:"size"`
LastModified time.Time `json:"last_modified"`
ETag string `json:"etag"`
ContentType string `json:"content_type"`
Metadata map[string]string `json:"metadata"`
}
ObjectMetadata represents object metadata
type OverallHealth ΒΆ
type OverallHealth struct {
Healthy bool `json:"healthy"`
BackendCount int `json:"backend_count"`
HealthyCount int `json:"healthy_count"`
UnhealthyCount int `json:"unhealthy_count"`
Backends map[string]BackendHealth `json:"backends"`
CheckedAt time.Time `json:"checked_at"`
}
OverallHealth represents overall storage health
type PathValidator ΒΆ
type PathValidator struct {
// contains filtered or unexported fields
}
PathValidator validates storage paths for security
func NewPathValidator ΒΆ
func NewPathValidator() *PathValidator
NewPathValidator creates a new path validator with default rules
func (*PathValidator) SanitizeKey ΒΆ
func (pv *PathValidator) SanitizeKey(key string) string
SanitizeKey sanitizes a key to make it safe
func (*PathValidator) ValidateContentType ΒΆ
func (pv *PathValidator) ValidateContentType(contentType string) error
ValidateContentType validates content type
func (*PathValidator) ValidateKey ΒΆ
func (pv *PathValidator) ValidateKey(key string) error
ValidateKey validates a storage key for security issues
type RateLimiter ΒΆ
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements token bucket rate limiting
func NewRateLimiter ΒΆ
func NewRateLimiter(config ResilienceConfig, metrics forge.Metrics) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ΒΆ
func (rl *RateLimiter) Allow() bool
Allow checks if a request is allowed
type ResilienceConfig ΒΆ
type ResilienceConfig struct {
// Retry configuration
MaxRetries int `yaml:"max_retries" json:"max_retries" default:"3"`
InitialBackoff time.Duration `yaml:"initial_backoff" json:"initial_backoff" default:"100ms"`
MaxBackoff time.Duration `yaml:"max_backoff" json:"max_backoff" default:"10s"`
BackoffMultiplier float64 `yaml:"backoff_multiplier" json:"backoff_multiplier" default:"2.0"`
// Circuit breaker configuration
CircuitBreakerEnabled bool `yaml:"circuit_breaker_enabled" json:"circuit_breaker_enabled" default:"true"`
CircuitBreakerThreshold uint32 `yaml:"circuit_breaker_threshold" json:"circuit_breaker_threshold" default:"5"`
CircuitBreakerTimeout time.Duration `yaml:"circuit_breaker_timeout" json:"circuit_breaker_timeout" default:"60s"`
CircuitBreakerHalfOpenMax uint32 `yaml:"circuit_breaker_half_open_max" json:"circuit_breaker_half_open_max" default:"3"`
// Rate limiting
RateLimitEnabled bool `yaml:"rate_limit_enabled" json:"rate_limit_enabled" default:"true"`
RateLimitPerSec int `yaml:"rate_limit_per_sec" json:"rate_limit_per_sec" default:"100"`
RateLimitBurst int `yaml:"rate_limit_burst" json:"rate_limit_burst" default:"200"`
// Timeout configuration
OperationTimeout time.Duration `yaml:"operation_timeout" json:"operation_timeout" default:"30s"`
}
ResilienceConfig configures resilience features
func DefaultResilienceConfig ΒΆ
func DefaultResilienceConfig() ResilienceConfig
DefaultResilienceConfig returns default resilience configuration
type ResilientStorage ΒΆ
type ResilientStorage struct {
// contains filtered or unexported fields
}
ResilientStorage wraps a storage backend with resilience features
func NewResilientStorage ΒΆ
func NewResilientStorage(backend Storage, config ResilienceConfig, logger forge.Logger, metrics forge.Metrics) *ResilientStorage
NewResilientStorage creates a resilient storage wrapper
func (*ResilientStorage) Copy ΒΆ
func (rs *ResilientStorage) Copy(ctx context.Context, srcKey, dstKey string) error
Copy copies with resilience
func (*ResilientStorage) Delete ΒΆ
func (rs *ResilientStorage) Delete(ctx context.Context, key string) error
Delete deletes with resilience
func (*ResilientStorage) Download ΒΆ
func (rs *ResilientStorage) Download(ctx context.Context, key string) (io.ReadCloser, error)
Download downloads with resilience
func (*ResilientStorage) GetCircuitBreakerState ΒΆ
func (rs *ResilientStorage) GetCircuitBreakerState() CircuitState
GetCircuitBreakerState returns circuit breaker state
func (*ResilientStorage) List ΒΆ
func (rs *ResilientStorage) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
List lists with resilience
func (*ResilientStorage) Metadata ΒΆ
func (rs *ResilientStorage) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
Metadata gets metadata with resilience
func (*ResilientStorage) Move ΒΆ
func (rs *ResilientStorage) Move(ctx context.Context, srcKey, dstKey string) error
Move moves with resilience
func (*ResilientStorage) PresignDownload ΒΆ
func (rs *ResilientStorage) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignDownload presigns download URL with resilience
func (*ResilientStorage) PresignUpload ΒΆ
func (rs *ResilientStorage) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignUpload presigns upload URL with resilience
func (*ResilientStorage) ResetCircuitBreaker ΒΆ
func (rs *ResilientStorage) ResetCircuitBreaker()
ResetCircuitBreaker resets the circuit breaker
func (*ResilientStorage) Upload ΒΆ
func (rs *ResilientStorage) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
Upload uploads with resilience
type S3Backend ΒΆ
type S3Backend struct {
// contains filtered or unexported fields
}
S3Backend implements storage using AWS S3
func NewS3Backend ΒΆ
func NewS3Backend(configMap map[string]interface{}, logger forge.Logger, metrics forge.Metrics) (*S3Backend, error)
NewS3Backend creates a new S3 storage backend
func (*S3Backend) PresignDownload ΒΆ
func (b *S3Backend) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignDownload generates a presigned URL for download
type S3Config ΒΆ
type S3Config struct {
Region string
Bucket string
Prefix string
AccessKeyID string
SecretAccessKey string
SessionToken string
Endpoint string // For S3-compatible services
UsePathStyle bool // For S3-compatible services
}
S3Config contains S3 configuration
type Storage ΒΆ
type Storage interface {
// Upload uploads an object
Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
// Download downloads an object
Download(ctx context.Context, key string) (io.ReadCloser, error)
// Delete deletes an object
Delete(ctx context.Context, key string) error
// List lists objects with a prefix
List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
// Metadata retrieves object metadata
Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
// Exists checks if an object exists
Exists(ctx context.Context, key string) (bool, error)
// Copy copies an object
Copy(ctx context.Context, srcKey, dstKey string) error
// Move moves an object
Move(ctx context.Context, srcKey, dstKey string) error
// PresignUpload generates a presigned URL for upload
PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
// PresignDownload generates a presigned URL for download
PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
}
Storage defines the unified storage interface
type StorageManager ΒΆ
type StorageManager struct {
// contains filtered or unexported fields
}
StorageManager manages multiple storage backends
func NewStorageManager ΒΆ
NewStorageManager creates a new storage manager
func (*StorageManager) Backend ΒΆ
func (m *StorageManager) Backend(name string) Storage
Backend returns a specific backend
func (*StorageManager) BackendHealth ΒΆ
func (m *StorageManager) BackendHealth(ctx context.Context, name string) (*BackendHealth, error)
BackendHealth returns health of a specific backend
func (*StorageManager) Copy ΒΆ
func (m *StorageManager) Copy(ctx context.Context, srcKey, dstKey string) error
Copy copies in the default backend
func (*StorageManager) Delete ΒΆ
func (m *StorageManager) Delete(ctx context.Context, key string) error
Delete deletes from the default backend
func (*StorageManager) Download ΒΆ
func (m *StorageManager) Download(ctx context.Context, key string) (io.ReadCloser, error)
Download downloads from the default backend
func (*StorageManager) GetURL ΒΆ
func (m *StorageManager) GetURL(ctx context.Context, key string) string
GetURL returns the URL for an object (CDN or direct)
func (*StorageManager) Health ΒΆ
func (m *StorageManager) Health(ctx context.Context) error
Health checks the health of all backends
func (*StorageManager) HealthDetailed ΒΆ
func (m *StorageManager) HealthDetailed(ctx context.Context, checkAll bool) (*OverallHealth, error)
HealthDetailed returns detailed health information
func (*StorageManager) List ΒΆ
func (m *StorageManager) List(ctx context.Context, prefix string, opts ...ListOption) ([]Object, error)
List lists from the default backend
func (*StorageManager) Metadata ΒΆ
func (m *StorageManager) Metadata(ctx context.Context, key string) (*ObjectMetadata, error)
Metadata gets metadata from the default backend
func (*StorageManager) Move ΒΆ
func (m *StorageManager) Move(ctx context.Context, srcKey, dstKey string) error
Move moves in the default backend
func (*StorageManager) PresignDownload ΒΆ
func (m *StorageManager) PresignDownload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignDownload generates a presigned download URL for the default backend
func (*StorageManager) PresignUpload ΒΆ
func (m *StorageManager) PresignUpload(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignUpload generates a presigned upload URL for the default backend
func (*StorageManager) Start ΒΆ
func (m *StorageManager) Start(ctx context.Context) error
Start initializes all storage backends
func (*StorageManager) Stop ΒΆ
func (m *StorageManager) Stop(ctx context.Context) error
Stop closes all storage backends
func (*StorageManager) Upload ΒΆ
func (m *StorageManager) Upload(ctx context.Context, key string, data io.Reader, opts ...UploadOption) error
Upload uploads to the default backend
type UploadOption ΒΆ
type UploadOption func(*UploadOptions)
UploadOption is a functional option for uploads
func WithContentType ΒΆ
func WithContentType(contentType string) UploadOption
WithContentType sets the content type
func WithMetadata ΒΆ
func WithMetadata(metadata map[string]string) UploadOption
WithMetadata sets metadata