registry

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 39 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseURL

func ParseURL(value string) (*url.URL, error)

ParseURL returns the URL of a volume's backend, which is a URL, such as s3://my.bucket/photos, or otherwise a directory, without a scheme, with any options after a "?", such as /mnt/media?readonly=true, which is made absolute, when it's relative, as the current directory's, and is a file URL, without a host, as its name isn't known, such as file:///mnt/media?readonly=true. On Windows, a directory with a drive, such as C:\media, or C:media, which is relative to the drive's current directory, isn't a URL whose scheme is its drive, and its URL's path has the drive, such as /C:/media. Returns gofiler.ErrBadParameter, without the value, which can have credentials, when it can't be parsed, and a value with "://" is a URL, not a directory, even when it can't be parsed.

func PatchURL

func PatchURL(volumeURL string, patch url.Values) (string, error)

PatchURL returns a volume's URL, with the patch of its options: each key replaces the option's values with its own, or, when it has none, removes the option, so it's the default (see gofiler.PatchValues)

func VolumeName

func VolumeName(u *url.URL) string

VolumeName returns the name of the volume of a URL, which is its name option, when it's set, such as s3://my.bucket/?name=photos, or otherwise its host, such as file://media/mnt/media or s3://photos/, or empty, when it has neither

Types

type MarkdownFunc

type MarkdownFunc func(ctx context.Context, r io.Reader, object *schema.Object) (*schema.Markdown, error)

MarkdownFunc reads a file's content, of the reader, as Markdown, and returns its start, and where the rest starts, when there's more, or ErrNotImplemented, when it can't be read as Markdown

type Opt

type Opt func(*opt) error

Opt is a functional option of the registry

func WithBackend

func WithBackend(backend gofiler.Backend) Opt

WithBackend adds a backend, which the volumes whose URLs have its scheme are opened with, such as one of another package, or program, which embeds the registry, of its package's Backend function, such as rss.Backend(). A scheme is of two characters or more, in lower case, and one which another backend has, such as one which is built in, is an error.

func WithBroadcaster

func WithBroadcaster(b *broadcaster.Broadcaster) Opt

WithBroadcaster sets the broadcaster which Run publishes the changes to the volumes to, which its owner runs, and serves, such as a server, which can share it with its other modules. Without it, the changes aren't published, and WatchObjects is ErrNotImplemented.

func WithCacheDir

func WithCacheDir(dir string) Opt

WithCacheDir sets the directory of the volumes' caches, which is created, where each volume's backend has a cache of its own, which is kept, so it isn't got again after a restart. Without it, the caches are in a temporary directory, which is removed once the registry is closed.

func WithClientOpts

func WithClientOpts(clientopts ...client.ClientOpt) Opt

WithClientOpts sets the client options of the backends which call other services over HTTP, such as Google's, which they're given as they are, such as a user agent, a tracer, of client.OptTracer, a trace, or a timeout, as a command's are, of server.Cmd's ClientEndpoint. The registry doesn't add its own tracer to them, so a request isn't traced twice, or left out of a trace it's given.

func WithCredentials

func WithCredentials(credentials credential.CredentialProvider) Opt

WithCredentials sets the provider of the credentials of the backends, which they look up of the names in their URLs, such as S3_SECRET, so the URLs don't have the credentials

func WithDebounce

func WithDebounce(delay time.Duration) Opt

WithDebounce sets how long a change to an object is held, until it's quiet for it, when its changes are merged, so an object which changes many times, such as a file which is written in parts, is one change, which is 250ms by default, or zero to send the changes at once. A change is held for at most two seconds, or the delay, when it's longer.

func WithMarkdown

func WithMarkdown(fn MarkdownFunc) Opt

WithMarkdown sets what reads a file's content as Markdown, such as a PDF's, of go-metadata, which Markdown does

func WithMetadataTask

func WithMetadataTask(task indexer.Task) Opt

WithMetadataTask sets the task which enriches the files of the volumes which are indexed with index=metadata, with their metadata, such as go-metadata's, which each volume's indexer does, apart from indexing it

func WithMeter

func WithMeter(meter metric.Meter) Opt

WithMeter sets the OpenTelemetry meter used for metrics.

func WithSchemes

func WithSchemes(schemes ...string) Opt

WithSchemes uses only the backends of the schemes, of those which are built in, and those of WithBackend, such as a server's --backend flag. A stored volume of another scheme is offline, as its backend isn't registered. A scheme which isn't a backend's is an error, which lists those which are. It can be repeated, and its schemes are added.

func WithStore

func WithStore(s store.Store) Opt

WithStore sets the store of the volumes, and their indexes, which is required. The registry mounts the volumes which are enabled in it, and a volume with the index option, such as index=folders, is indexed in it.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer of the backends' operations, such as fs's, and S3's

func WithWorker

func WithWorker(name string) Opt

WithWorker sets the name of the worker, such as the server's, which is in the metrics, so those of the workers are told apart, and which is the hostname by default

type Registry

type Registry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, opts ...Opt) (*Registry, error)

New creates a registry of the backends of volumes

func (*Registry) Actions

func (self *Registry) Actions() []gofiler.Action

Actions returns nil, as a registry's actions are of its volumes, each of its own backend's

func (*Registry) Backend added in v0.5.2

func (self *Registry) Backend(scheme string) (gofiler.Backend, error)

Backend returns the backend of the scheme, or ErrNotFound, when there's none, such as one which isn't run

func (*Registry) Backends

func (self *Registry) Backends() []schema.Backend

Backends returns the backends which volumes can be created of, in order of their schemes, with what each is, the media type of its icon, when it has one, and its default options

func (*Registry) CallAction

func (self *Registry) CallAction(ctx context.Context, volume, name string, input json.RawMessage) (*schema.Object, error)

CallAction runs an action of a volume's backend, of its name, with its input, which is JSON of its schema, and returns the object it created or changed, with the volume's name. An action which the backend doesn't have is ErrNotFound, and a volume which isn't mounted, or is offline, is as ListActions'.

func (*Registry) Clone

func (self *Registry) Clone(context.Context, url.Values) (gofiler.Filer, error)

Clone returns ErrNotImplemented, as a registry can't be cloned: its volumes are cloned to change their options, with Update

func (*Registry) CreateObject

func (self *Registry) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (*schema.Object, error)

CreateObject creates an object in the volume named by the request

func (*Registry) CreateVolume

func (self *Registry) CreateVolume(ctx context.Context, volume schema.VolumeMeta) (*schema.Volume, error)

CreateVolume stores a volume, which is mounted by Run, when it's enabled, and returns it, before it's mounted. Its backend is created from its URL first, which checks it, and then closed, and its URL is the backend's, with each of its options, defaults too, and its index option. Returns ErrConflict when the volume is stored already, and ErrBadParameter when its name isn't an identifier, or its URL's, or the backend can't be created.

func (*Registry) DeleteObjects

DeleteObjects deletes an object, or the objects beneath a directory, in the volume named by the request

func (*Registry) DeleteVolume

func (self *Registry) DeleteVolume(ctx context.Context, name string) (*schema.Volume, error)

DeleteVolume removes a volume from the store, with its index, which Run unmounts, and returns it, as it was, before it's unmounted. Returns ErrNotFound when it isn't stored.

func (*Registry) Description

func (self *Registry) Description() string

Description returns what the registry is, its volumes, as each volume's backend has its own description

func (*Registry) GetArtwork added in v0.6.0

func (self *Registry) GetArtwork(ctx context.Context, hash string, data bool) (*schema.Artwork, error)

GetArtwork returns the artwork of the hash, which objects link to (see schema.Object's Artwork), with its data, when it's asked for, or ErrNotFound, or ErrBadParameter when the hash isn't one

func (*Registry) GetObject

func (self *Registry) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)

GetObject returns an object in the volume named by the request

func (*Registry) GetVolume

func (self *Registry) GetVolume(ctx context.Context, name string) (*schema.Volume, error)

GetVolume returns a volume of the store, with its index, when it's mounted and indexed, and why it isn't enabled, when it's enabled but offline, or can't be mounted. Returns ErrNotFound when it isn't stored.

func (*Registry) Keys

func (self *Registry) Keys() []string

Keys returns the volumes which are registered, and can be used, in order, which doesn't include those which are being added or removed

func (*Registry) List

func (self *Registry) List(ctx context.Context, req schema.ObjectListRequest) (_ *schema.ObjectList, err error)

List returns a page of the objects beneath a path in the volume named by the request, of at most its limit, which defaults to and is capped at schema.ObjectListLimit. When there are more, Next is the key of the last object, which the next page starts after, with StartAfter.

func (*Registry) ListActions

func (self *Registry) ListActions(ctx context.Context, volume string) (*schema.ActionList, error)

ListActions returns the actions of a volume's backend, or, when the volume is empty, of every volume which is mounted, and online, in order of their volumes, and their names, which is empty for a backend which has none, such as a filesystem. A volume which isn't mounted is as GetObject's, and one which is offline, as its watch failed, is ErrServiceUnavailable, as actions are done of its backend, whose changes are of its watch.

func (*Registry) ListObjects

ListObjects lists the objects in the volume named by the request. The volume's backend isn't closed until the iterator is closed, or the volume is removed, when the iterator is closed, and returns fs.ErrClosed.

func (*Registry) ListVolumes

func (self *Registry) ListVolumes(ctx context.Context) ([]schema.Volume, error)

ListVolumes returns the volumes of the store, in order of their names, as GetVolume returns them, which includes those which aren't enabled. Their indexes' states are read at once, a few at a time, as each is a query of the store.

func (*Registry) Markdown

func (self *Registry) Markdown(ctx context.Context, read gofiler.ReadObjectFunc, object *schema.Object) (*schema.Markdown, error)

Markdown reads the content of the object, which ReadObject returned, of its function, as Markdown, and returns its start, and where the rest starts, when there's more. It's ErrNotImplemented when the registry has no way to read Markdown, or the object can't be read as it.

func (*Registry) ReadObject

ReadObject returns an object in the volume named by the request, and a function which reads its content, which keeps the volume's backend from being closed while it reads, and is cancelled when the volume is removed. Returns ErrNotFound from the function when the volume was removed, or added again, since the object was returned.

func (*Registry) Run

func (self *Registry) Run(ctx context.Context, logger *slog.Logger) (err error)

Run watches the volumes, and publishes their changes, until the context is cancelled, when it stops watching them, and closes the registry: it removes and closes the volumes, cancelling and waiting for the calls to With which are using them, and returns their errors. The registry can't be used, or run, once it's closed, which is fs.ErrClosed.

func (*Registry) Running

func (self *Registry) Running() bool

Running returns true when Run is running

func (*Registry) Schemes

func (self *Registry) Schemes() []string

Schemes returns the schemes of the URLs which backends can be created from, in order, such as "file", of those which are built in, and those of WithBackend

func (*Registry) Search

func (self *Registry) Search(ctx context.Context, text string, page schema.OffsetLimit) (*schema.SearchResponse, error)

Search returns the objects of the volumes which are mounted, which match the query, of its text (see schema.Query), best first, of the page, whose limit defaults to, and is capped at, schema.SearchLimit, and how many match, of every page. Returns ErrBadParameter of text which isn't a query, such as of a quote which doesn't end.

func (*Registry) URL

func (self *Registry) URL() *url.URL

URL returns the URL of the registry, which is filer:, as it's the filer of every volume, whose URLs are those of their backends

func (*Registry) UpdateVolume

func (self *Registry) UpdateVolume(ctx context.Context, volume schema.VolumeMeta) (*schema.Volume, error)

UpdateVolume stores a volume's URL, and whether it's enabled, which Run mounts again, or unmounts, and returns it, before it's mounted. Its backend is created from its URL first, which checks it, as CreateVolume does. Its scheme can't be changed, which is ErrBadParameter. A volume whose backend is another, of its host or path, doesn't keep its index. A volume which is offline is opened again, even when it isn't changed, such as once its user has signed in again. Returns ErrNotFound when the volume isn't stored, or is deleted meanwhile.

func (*Registry) WatchObjects

func (self *Registry) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

WatchObjects sends each change to the objects of every volume to the channel, of the broadcaster's changes, until the context is cancelled. A call which falls behind is sent a rescan of each volume it missed a change of. Returns ErrNotImplemented without a broadcaster, as the changes aren't published, and fs.ErrClosed when the registry is closed, or the broadcaster stops running.

func (*Registry) With

func (self *Registry) With(ctx context.Context, volume string, fn func(context.Context, gofiler.Filer) error) error

With calls fn with the backend for the specified volume, or returns an error if the volume is not registered. The backend is not closed until fn returns, so fn must finish using the backend before it returns. The context passed to fn is cancelled when ctx is cancelled, or when the volume is removed, so that long-running operations do not delay removing it. The registry is not locked while fn runs, so fn may call other registry methods, but Del or Update of its own volume, with the context passed to it, is ErrConflict, as they'd wait for fn to return.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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