Documentation ¶
Index ¶
- Constants
- type ErrDuplicateID
- type Metadata
- type Repository
- func (r *Repository) Add(m *media.Media) error
- func (r *Repository) Close() error
- func (r *Repository) Create(b []byte, m meta.Metadata) (*media.Media, error)
- func (r *Repository) Find(query string, format media.Format, amount int) []*media.Media
- func (r *Repository) Get(id uuid.UUID) *media.Media
- func (r *Repository) ID() string
- func (r *Repository) Items() []*media.Media
- func (r *Repository) LockPath() string
- func (r *Repository) Memory() bool
- func (r *Repository) Meta() Metadata
- func (r *Repository) Path() string
- func (r *Repository) Random(n int) []*media.Media
- func (r *Repository) Remove(id uuid.UUID) error
Constants ¶
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 Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is a media repository.
func NewFile ¶
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 ¶
Create creates and inserts new media into the repository. Returns errors.ErrUnsupported for repositories without a backing storage directory.
func (*Repository) Find ¶
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) 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).