loader

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyInstalled = errors.New("already installed")
	ErrNotInstalled     = errors.New("not installed")
	ErrNotInRepo        = errors.New("not in the repository")
	ErrBadName          = errors.New("invalid plugin name")
	// ErrBadFile is returned when a file to install is not a Linux plugin
	// .so (wrong magic).
	ErrBadFile = errors.New("not a plugin file")
	// ErrNeedsRestart is returned when new plugin bytes sit at a path this
	// process has already opened: a loaded Go module cannot be swapped, so
	// the file is kept and loads on the next start.
	ErrNeedsRestart = errors.New("plugin file already open in this process; restart to swap it")
)

Errors callers branch on.

Functions

func Explain added in v0.1.1

func Explain(err error) (zh, en string)

Explain turns loader errors into a short reason in both languages.

func ValidName added in v0.1.1

func ValidName(name string) bool

ValidName reports whether name is a usable external plugin name.

Types

type IndexEntry added in v0.1.1

type IndexEntry struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	DescEN      string `json:"desc_en,omitempty"`
	Version     string `json:"version"`
}

IndexEntry is one plugin in the repository index (plugins.json).

type LoadedPlugin

type LoadedPlugin struct {
	Plugin   pkgplugin.Plugin
	Handle   *goplugin.Plugin
	Path     string
	Metadata *pkgplugin.PluginMetadata
	LoadedAt time.Time
}

LoadedPlugin represents a loaded .so plugin.

type Loader

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

Loader loads/unloads/manages external plugins from .so files. Every operation is serialized, so commands and bot taps can race freely.

func NewLoader

func NewLoader(dir string, mgr pkgplugin.Manager) *Loader

NewLoader creates a new plugin loader.

func (*Loader) Failed added in v0.1.1

func (l *Loader) Failed() map[string]string

Failed returns plugin files in the directory that did not load, with the reason.

func (*Loader) GetAvailable

func (l *Loader) GetAvailable() ([]string, error)

GetAvailable returns .so files in the plugins dir that are NOT loaded.

func (*Loader) GetInstalled

func (l *Loader) GetInstalled() ([]string, error)

GetInstalled returns all .so files in the plugins dir.

func (*Loader) GetLoaded

func (l *Loader) GetLoaded() map[string]*LoadedPlugin

GetLoaded returns all currently loaded plugins.

func (*Loader) GetPluginDir

func (l *Loader) GetPluginDir() string

GetPluginDir returns the plugin directory path.

func (*Loader) Index added in v0.1.1

func (l *Loader) Index(ctx context.Context, fresh bool) ([]IndexEntry, error)

Index fetches the repository index, sorted by name. A fetch within the last minute is reused unless fresh is set.

func (*Loader) Install

func (l *Loader) Install(ctx context.Context, name string) error

Install downloads a plugin .so from the registry.

func (*Loader) InstallAndLoad added in v0.1.1

func (l *Loader) InstallAndLoad(ctx context.Context, name string) error

InstallAndLoad downloads (when missing) and loads a plugin. Installed always means loaded: a file that fails to load is deleted again, except a file that was swapped for new bytes at an already-open path — those are kept and load on the next start.

func (*Loader) InstallFileAndLoad added in v0.1.3

func (l *Loader) InstallFileAndLoad(ctx context.Context, src string) error

InstallFileAndLoad installs a plugin from a local .so file (downloaded from a replied message), then loads it. The source file is not modified. The file's name is ignored: the plugin is installed under the module name recorded in the .so itself, so file name and plugin name can never drift apart.

func (*Loader) IsLoaded

func (l *Loader) IsLoaded(name string) bool

IsLoaded checks if a plugin is loaded.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, path string) error

Load loads a single plugin from a .so file path.

func (*Loader) LoadAll

func (l *Loader) LoadAll(ctx context.Context) error

LoadAll loads all .so plugins from the plugins directory. Files that fail are remembered (see Failed) instead of aborting the rest.

func (*Loader) LoadByName

func (l *Loader) LoadByName(ctx context.Context, name string) error

LoadByName loads a plugin by name from the plugins directory.

func (*Loader) LoadedNames added in v0.1.1

func (l *Loader) LoadedNames() []string

LoadedNames returns the loaded plugin names, sorted.

func (*Loader) Reload added in v0.1.1

func (l *Loader) Reload(ctx context.Context, name string) error

Reload unloads and loads one plugin again, re-reading its settings.

func (*Loader) Remove

func (l *Loader) Remove(ctx context.Context, name string) error

Remove unloads a plugin and deletes its .so file. Its settings stay in data/<name>/ so a reinstall picks them up again.

func (*Loader) RepoURL added in v0.1.1

func (l *Loader) RepoURL() string

RepoURL returns the configured plugin registry base URL.

func (*Loader) SetRepoURL

func (l *Loader) SetRepoURL(url string)

SetRepoURL sets the plugin registry URL.

func (*Loader) Unload

func (l *Loader) Unload(ctx context.Context, name string) error

Unload unloads a plugin by name.

type NameMismatchError added in v0.1.3

type NameMismatchError struct {
	File   string
	Plugin string
}

NameMismatchError is returned when a .so file's name differs from the Name() of the plugin inside it. Every loader entry — loaded, failed, settings, the panels — is keyed by file name, so the two must match.

func (*NameMismatchError) Error added in v0.1.3

func (e *NameMismatchError) Error() string

Jump to

Keyboard shortcuts

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