loader

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 17 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")
)

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.

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.

Jump to

Keyboard shortcuts

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