storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(ctx context.Context, s Storage, prefix string, w io.Writer) error

Backup writes all files under prefix to a tar.gz stream

func Restore

func Restore(ctx context.Context, s Storage, destPrefix string, r io.Reader) error

Restore reads a tar.gz archive and writes files to storage under destPrefix

Types

type FileInfo

type FileInfo struct {
	Path        string
	Size        int64
	ETag        string
	ContentType string
	IsDir       bool
}

FileInfo holds metadata for a stored object

type ListOptions

type ListOptions struct {
	Prefix    string
	Recursive bool
	Limit     int
}

ListOptions control listing behavior

type Local

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

Local implements Storage using the local filesystem

func NewLocal

func NewLocal(root string) (*Local, error)

NewLocal creates a new Local storage at root

func (*Local) Delete

func (l *Local) Delete(ctx context.Context, path string) error

func (*Local) DeletePrefix

func (l *Local) DeletePrefix(ctx context.Context, prefix string) error

func (*Local) Get

func (l *Local) Get(ctx context.Context, path string) (io.ReadCloser, *FileInfo, error)

func (*Local) List

func (l *Local) List(ctx context.Context, opts ListOptions) ([]FileInfo, error)

func (*Local) MakeDir

func (l *Local) MakeDir(ctx context.Context, path string) error

func (*Local) Put

func (l *Local) Put(ctx context.Context, path string, r io.Reader, size int64, contentType string) error

func (*Local) RemoveDir

func (l *Local) RemoveDir(ctx context.Context, path string) error

func (*Local) Stat

func (l *Local) Stat(ctx context.Context, path string) (*FileInfo, error)

type Manager

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

Manager provides named drivers and default storage

func NewManager

func NewManager() *Manager

NewManager creates a new storage manager

func (*Manager) Default

func (m *Manager) Default() Storage

Default returns default storage driver

func (*Manager) Driver

func (m *Manager) Driver(name string) Storage

Driver returns a named driver

func (*Manager) Register

func (m *Manager) Register(name string, driver Storage, setDefault bool)

Register registers a storage driver

type MinIOConfig

type MinIOConfig struct {
	Endpoint        string
	AccessKeyID     string
	SecretAccessKey string
	Secure          bool
	Bucket          string
	Region          string
}

type MinIOStorage

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

func NewMinIOStorage

func NewMinIOStorage(ctx context.Context, cfg MinIOConfig) (*MinIOStorage, error)

func (*MinIOStorage) Delete

func (m *MinIOStorage) Delete(ctx context.Context, path string) error

func (*MinIOStorage) DeletePrefix

func (m *MinIOStorage) DeletePrefix(ctx context.Context, prefix string) error

func (*MinIOStorage) Get

func (m *MinIOStorage) Get(ctx context.Context, path string) (io.ReadCloser, *FileInfo, error)

func (*MinIOStorage) List

func (m *MinIOStorage) List(ctx context.Context, opts ListOptions) ([]FileInfo, error)

func (*MinIOStorage) MakeDir

func (m *MinIOStorage) MakeDir(ctx context.Context, path string) error

func (*MinIOStorage) Put

func (m *MinIOStorage) Put(ctx context.Context, path string, r io.Reader, size int64, contentType string) error

func (*MinIOStorage) RemoveDir

func (m *MinIOStorage) RemoveDir(ctx context.Context, path string) error

func (*MinIOStorage) Stat

func (m *MinIOStorage) Stat(ctx context.Context, path string) (*FileInfo, error)

type S3Config

type S3Config struct {
	Region          string
	Bucket          string
	Endpoint        string
	ForcePathStyle  bool
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

type S3Storage

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

func NewS3Storage

func NewS3Storage(ctx context.Context, cfg S3Config) (*S3Storage, error)

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, path string) error

func (*S3Storage) DeletePrefix

func (s *S3Storage) DeletePrefix(ctx context.Context, prefix string) error

func (*S3Storage) Get

func (s *S3Storage) Get(ctx context.Context, path string) (io.ReadCloser, *FileInfo, error)

func (*S3Storage) List

func (s *S3Storage) List(ctx context.Context, opts ListOptions) ([]FileInfo, error)

func (*S3Storage) MakeDir

func (s *S3Storage) MakeDir(ctx context.Context, path string) error

func (*S3Storage) Put

func (s *S3Storage) Put(ctx context.Context, path string, r io.Reader, size int64, contentType string) error

func (*S3Storage) RemoveDir

func (s *S3Storage) RemoveDir(ctx context.Context, path string) error

func (*S3Storage) Stat

func (s *S3Storage) Stat(ctx context.Context, path string) (*FileInfo, error)

type Storage

type Storage interface {
	// Put stores data at path. Creates directories if needed
	Put(ctx context.Context, path string, r io.Reader, size int64, contentType string) error
	// Get returns a ReadCloser for path
	Get(ctx context.Context, path string) (io.ReadCloser, *FileInfo, error)
	// Stat returns metadata for path
	Stat(ctx context.Context, path string) (*FileInfo, error)
	// Delete removes a single file
	Delete(ctx context.Context, path string) error
	// DeletePrefix removes all files under a prefix
	DeletePrefix(ctx context.Context, prefix string) error
	// List lists files under a prefix
	List(ctx context.Context, opts ListOptions) ([]FileInfo, error)
	// MakeDir creates a folder (no-op for object stores)
	MakeDir(ctx context.Context, path string) error
	// RemoveDir removes a folder (best-effort)
	RemoveDir(ctx context.Context, path string) error
}

Storage abstracts file storage operations

Jump to

Keyboard shortcuts

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