Documentation
¶
Overview ¶
Package storage provides dynamically configured file storage backends.
Index ¶
- Constants
- Variables
- func Active(ctx context.Context) (Driver, Backend, error)
- func MockStorage(put func(context.Context, string, io.Reader, int64, string) error, ...) func()
- func PublishCacheInvalidation(ctx context.Context)
- func ResetCache()
- func SaveActiveConfig(ctx context.Context, cfg Config) error
- func ValidateConfig(cfg Config) error
- type Backend
- type Config
- type Driver
- type LocalConfig
- type Object
- type ObjectConfig
- type PutResult
- type WebDAVConfig
Constants ¶
const ConfigInvalidationChannel = "storage:config_invalidation"
ConfigInvalidationChannel is the Redis pub/sub channel used to evict storage caches cluster-wide.
Variables ¶
var ( // IsEnabledFunc preserves the legacy S3 test hook while tests migrate to backend injection. IsEnabledFunc = func() bool { return false } )
Functions ¶
func Active ¶ added in v1.1.0
Active returns the configured active driver and backend, using an in-memory cache with 5s TTL.
func MockStorage ¶
func MockStorage( put func(context.Context, string, io.Reader, int64, string) error, get func(context.Context, string) (*Object, error), deleteObject func(context.Context, string) error, ) func()
MockStorage replaces object operations for package tests and returns a restore function.
func PublishCacheInvalidation ¶ added in v1.1.0
PublishCacheInvalidation broadcasts cache eviction to all nodes in the cluster via Redis.
func ResetCache ¶ added in v1.1.0
func ResetCache()
ResetCache clears the local cache for storage configuration and client singletons.
func SaveActiveConfig ¶ added in v1.1.0
SaveActiveConfig persists the active storage configuration.
func ValidateConfig ¶ added in v1.1.0
ValidateConfig validates the selected backend configuration.
Types ¶
type Backend ¶ added in v1.1.0
type Backend interface {
Put(ctx context.Context, key string, body io.Reader, size int64, contentType string) (PutResult, error)
Get(ctx context.Context, key string) (*Object, error)
Delete(ctx context.Context, key string) error
Test(ctx context.Context) error
}
Backend defines storage operations used by the upload domain.
type Config ¶ added in v1.1.0
type Config struct {
Driver Driver `json:"driver"`
Local LocalConfig `json:"local"`
S3 ObjectConfig `json:"s3"`
R2 ObjectConfig `json:"r2"`
MinIO ObjectConfig `json:"minio"`
OSS ObjectConfig `json:"oss"`
WebDAV WebDAVConfig `json:"webdav"`
}
Config contains all storage backends and the currently active driver.
func DefaultConfig ¶ added in v1.1.0
func DefaultConfig() Config
DefaultConfig returns the local-storage default configuration.
func LoadConfig ¶ added in v1.1.0
LoadConfig loads the active storage configuration.
func MaskSecrets ¶ added in v1.1.0
MaskSecrets replaces stored credentials with placeholders for API responses.
func MergeMaskedSecrets ¶ added in v1.1.0
MergeMaskedSecrets restores unchanged secrets from the current configuration.
type Driver ¶ added in v1.1.0
type Driver string
Driver identifies a supported storage backend.
const ( // DriverLocal stores files on the local filesystem. DriverLocal Driver = "local" // DriverS3 stores files in an S3-compatible object store. DriverS3 Driver = "s3" // DriverR2 stores files in Cloudflare R2. DriverR2 Driver = "r2" // DriverMinIO stores files in MinIO. DriverMinIO Driver = "minio" // DriverOSS stores files in Aliyun OSS. DriverOSS Driver = "oss" // DriverWebDAV stores files through WebDAV. DriverWebDAV Driver = "webdav" // ConfigMask replaces secrets returned to the frontend. ConfigMask = "******" )
type LocalConfig ¶ added in v1.1.0
type LocalConfig struct {
Root string `json:"root"`
}
LocalConfig configures local filesystem storage.
type Object ¶ added in v1.1.0
type Object struct {
CachePath string
Body io.ReadCloser
ContentLength int64
ContentType string
}
Object describes a readable stored object.
type ObjectConfig ¶ added in v1.1.0
type ObjectConfig struct {
Endpoint string `json:"endpoint"`
Region string `json:"region"`
Bucket string `json:"bucket"`
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
AccountID string `json:"account_id,omitempty"`
PathStyle bool `json:"path_style"`
KeyPrefix string `json:"key_prefix"`
CDNURL string `json:"cdn_url"`
}
ObjectConfig configures S3-compatible or OSS object storage.