Documentation
¶
Overview ¶
Package storage stores downloaded chapter files on configurable backends: the local filesystem (which includes mounted network shares) and S3-compatible object storage. Files are addressed by key (a slash-separated path); every backend writes atomically and reads with random access, so the reader can open archives without downloading them whole.
Index ¶
- Constants
- Variables
- type Config
- type File
- type Local
- type LocalConfig
- type Manager
- func (m *Manager) Backend(ctx context.Context, id string) (Storage, error)
- func (m *Manager) Create(ctx context.Context, n NewStorage) (db.Storage, error)
- func (m *Manager) Default(ctx context.Context) (db.Storage, Storage, error)
- func (m *Manager) Delete(ctx context.Context, id string) error
- func (m *Manager) EnsureDefault(ctx context.Context, root string) error
- func (m *Manager) Get(ctx context.Context, id string) (db.Storage, error)
- func (m *Manager) List(ctx context.Context) ([]db.Storage, error)
- func (m *Manager) SetDefault(ctx context.Context, id string) error
- func (m *Manager) Test(ctx context.Context, id string) error
- func (m *Manager) Update(ctx context.Context, id, name string, cfg Config, secret string) (db.Storage, error)
- type NewStorage
- type S3
- type S3Config
- type Storage
Constants ¶
const ( KindLocal = "local" KindS3 = "s3" )
Kinds of storage.
Variables ¶
var ( ErrUnknown = errors.New("storage: no such storage") ErrIDTaken = errors.New("storage: a storage with this ID exists") ErrInvalidID = errors.New("storage: the ID must be lowercase letters, digits, '-' or '_' (up to 40)") ErrInUse = errors.New("storage: files are stored here; move them first") ErrIsDefault = errors.New("storage: the default storage can't be removed; make another the default first") ErrBadConfig = errors.New("storage: invalid settings") ErrNoDefault = errors.New("storage: no default storage") ErrRootNeeded = errors.New("storage: a local storage needs an absolute root directory") )
Errors callers map to responses.
var ErrNotFound = errors.New("storage: not found")
ErrNotFound is a key with no file.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Local *LocalConfig
S3 *S3Config
}
Config is a storage's settings: Local for local, S3 for S3.
type Local ¶
type Local struct {
Root string
}
Local stores files under a directory.
type LocalConfig ¶
type LocalConfig struct {
Root string `json:"root"`
}
LocalConfig is a local storage's settings.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps the configured storages.
func NewManager ¶
NewManager returns the storage manager.
func (*Manager) EnsureDefault ¶
EnsureDefault creates a local storage at root as the default when there is no storage yet.
func (*Manager) SetDefault ¶
SetDefault makes a storage the default for new downloads.
type NewStorage ¶
type NewStorage struct {
ID, Name, Kind string
Config Config
// Secret is the S3 secret access key.
Secret string
}
NewStorage is a storage to create.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 stores files in an S3-compatible bucket. Object writes are atomic.
type S3Config ¶
type S3Config struct {
// Endpoint is the service's URL, e.g. "https://s3.example.com".
Endpoint string `json:"endpoint"`
Region string `json:"region,omitempty"`
Bucket string `json:"bucket"`
// Prefix is prepended to every key, e.g. "panelarr/".
Prefix string `json:"prefix,omitempty"`
AccessKey string `json:"access_key"`
// PathStyle addresses the bucket in the path (most self-hosted
// services need it).
PathStyle bool `json:"path_style"`
}
S3Config is how to reach an S3-compatible bucket.
type Storage ¶
type Storage interface {
// Put stores the file at path under key, replacing nothing until it is
// complete: readers see the old file or the new one, never a partial
// one.
Put(ctx context.Context, key, path string) error
// Open opens a stored file for random access.
Open(ctx context.Context, key string) (File, error)
// Delete removes a file; a missing file is not an error.
Delete(ctx context.Context, key string) error
// Test checks the backend can write, read and delete.
Test(ctx context.Context) error
}
Storage is one storage backend.