repo

package
v0.0.0-...-93660c8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthKey is an authentication key metadata key.
	AuthKey = "auth_key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrDuplicateID

type ErrDuplicateID struct {
	// ID is the offending ID.
	ID string
	// Repo is the repository ID.
	Repo string
}

ErrDuplicateID is an error about a duplicate media ID in a repository.

func (*ErrDuplicateID) Error

func (edi *ErrDuplicateID) Error() string

Error returns the string representation of the error.

type Metadata

type Metadata map[string]string

Metadata is repository metadata.

func (Metadata) Value

func (m Metadata) Value(key string) (string, bool)

Value looks up a metadata value by key, returns false if the lookup failed.

type Repository

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

Repository is a media repository.

func NewFile

func NewFile(id, path, lockPath string, meta Metadata, logger *zap.Logger) (*Repository, error)

NewFile creates a Repository persisted to a lock file. If lockPath exists, its content is loaded into the repository.

func NewMemory

func NewMemory(id string, meta Metadata, logger *zap.Logger) *Repository

NewMemory creates a Repository without a backing lock file and storage directory.

func (*Repository) Add

func (r *Repository) Add(m *media.Media) error

Add inserts new media into the repository.

func (*Repository) Close

func (r *Repository) Close() error

Close cleans up after the repository. The repository should not be used anymore after calling Close.

func (*Repository) Create

func (r *Repository) Create(b []byte, m meta.Metadata) (*media.Media, error)

Create creates and inserts new media into the repository. Returns errors.ErrUnsupported for repositories without a backing storage directory.

func (*Repository) Find

func (r *Repository) Find(query string, format media.Format, amount int) []*media.Media

Find tries to find media by a metadata query (meta.Matchable) and a format, returns nil if nothing was found. Supplying media.FormatUnknown means any format should be accepted.

func (*Repository) Get

func (r *Repository) Get(id uuid.UUID) *media.Media

Get tries to find media by its ID, returns nil if nothing was found.

func (*Repository) ID

func (r *Repository) ID() string

ID returns the ID of the repository.

func (*Repository) Items

func (r *Repository) Items() []*media.Media

Items returns all pieces of media in the repository.

func (*Repository) LockPath

func (r *Repository) LockPath() string

LockPath returns the lock file path of the repository. Returns an empty string if it is an in-memory repository (Memory).

func (*Repository) Memory

func (r *Repository) Memory() bool

Memory returns whether this repository is only in memory (without a backing lock file).

func (*Repository) Meta

func (r *Repository) Meta() Metadata

Meta returns the repository metadata, may be nil.

func (*Repository) Path

func (r *Repository) Path() string

Path returns the storage directory path of the repository. Returns an empty string if it is an in-memory repository (Memory).

func (*Repository) Random

func (r *Repository) Random(n int) []*media.Media

Random picks N random media out of the repository.

func (*Repository) Remove

func (r *Repository) Remove(id uuid.UUID) error

Remove removes media from the repository by its ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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