storage

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBackendNotFound  = errors.New("storage backend not found")
	ErrNoDefaultBackend = errors.New("no default storage backend configured")
	ErrKeyNotFound      = errors.New("key not found in storage")
	ErrInvalidConfig    = errors.New("invalid storage configuration")
	ErrBackendNotReady  = errors.New("storage backend not ready")
	ErrUnsupportedOp    = errors.New("operation not supported by this backend")
)

Common storage errors

Functions

This section is empty.

Types

type StorageBackend

type StorageBackend interface {
	// Init initializes the storage backend with configuration
	Init(config map[string]interface{}) error

	// Save stores data to the storage backend at the specified key/path
	Save(ctx context.Context, key string, data io.Reader) error

	// Load retrieves data from the storage backend for the given key/path
	Load(ctx context.Context, key string) (io.ReadCloser, error)

	// Delete removes data from the storage backend for the given key/path
	Delete(ctx context.Context, key string) error

	// Exists checks if data exists at the given key/path in the storage backend
	Exists(ctx context.Context, key string) (bool, error)

	// List returns a list of keys with the given prefix
	List(ctx context.Context, prefix string) ([]string, error)

	// Close cleans up any resources used by the storage backend
	Close() error
}

StorageBackend defines the interface for different storage backends This allows for flexible storage options like local filesystem, cloud storage, etc.

type StorageConfig

type StorageConfig struct {
	// Type specifies the storage backend type (filesystem, s3, redis, memory)
	Type string `json:"type" yaml:"type"`

	// Config holds backend-specific configuration
	Config map[string]interface{} `json:"config" yaml:"config"`
}

StorageConfig holds common configuration options for storage backends

type StorageManager

type StorageManager struct {
	// contains filtered or unexported fields
}

StorageManager manages multiple storage backends

func NewStorageManager

func NewStorageManager() *StorageManager

NewStorageManager creates a new storage manager

func (*StorageManager) Close

func (sm *StorageManager) Close() error

Close closes all registered backends

func (*StorageManager) Delete

func (sm *StorageManager) Delete(ctx context.Context, key string) error

Delete deletes data using the default backend

func (*StorageManager) Exists

func (sm *StorageManager) Exists(ctx context.Context, key string) (bool, error)

Exists checks if data exists using the default backend

func (*StorageManager) GetBackend

func (sm *StorageManager) GetBackend(name string) (StorageBackend, error)

GetBackend returns a storage backend by name

func (*StorageManager) GetDefault

func (sm *StorageManager) GetDefault() (StorageBackend, error)

GetDefault returns the default storage backend

func (*StorageManager) List

func (sm *StorageManager) List(ctx context.Context, prefix string) ([]string, error)

List lists keys using the default backend

func (*StorageManager) Load

func (sm *StorageManager) Load(ctx context.Context, key string) (io.ReadCloser, error)

Load loads data using the default backend

func (*StorageManager) Register

func (sm *StorageManager) Register(name string, backend StorageBackend) error

Register registers a storage backend with a given name

func (*StorageManager) Save

func (sm *StorageManager) Save(ctx context.Context, key string, data io.Reader) error

Save saves data using the default backend

func (*StorageManager) SetDefault

func (sm *StorageManager) SetDefault(name string) error

SetDefault sets the default storage backend

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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