storage

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package storage provides dynamically configured file storage backends.

Index

Constants

View Source
const ConfigInvalidationChannel = "storage:config_invalidation"

ConfigInvalidationChannel is the Redis pub/sub channel used to evict storage caches cluster-wide.

Variables

View Source
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

func Active(ctx context.Context) (Driver, Backend, error)

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

func PublishCacheInvalidation(ctx context.Context)

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

func SaveActiveConfig(ctx context.Context, cfg Config) error

SaveActiveConfig persists the active storage configuration.

func ValidateConfig added in v1.1.0

func ValidateConfig(cfg Config) error

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.

func NewBackend added in v1.1.0

func NewBackend(ctx context.Context, cfg Config, driver Driver) (Backend, error)

NewBackend constructs a concrete backend from configuration.

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

func LoadConfig(ctx context.Context) (Config, error)

LoadConfig loads the active storage configuration.

func MaskSecrets added in v1.1.0

func MaskSecrets(cfg Config) Config

MaskSecrets replaces stored credentials with placeholders for API responses.

func MergeMaskedSecrets added in v1.1.0

func MergeMaskedSecrets(next, current Config) Config

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.

type PutResult added in v1.1.0

type PutResult struct {
	Key    string
	Bucket string
}

PutResult describes the result of a successful Put operation.

type WebDAVConfig added in v1.1.0

type WebDAVConfig struct {
	Endpoint string `json:"endpoint"`
	Username string `json:"username"`
	Password string `json:"password"`
	BasePath string `json:"base_path"`
}

WebDAVConfig configures WebDAV storage.

Jump to

Keyboard shortcuts

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