Documentation
¶
Index ¶
- Variables
- func Explain(err error) (zh, en string)
- func ValidName(name string) bool
- type IndexEntry
- type LoadedPlugin
- type Loader
- func (l *Loader) Failed() map[string]string
- func (l *Loader) GetAvailable() ([]string, error)
- func (l *Loader) GetInstalled() ([]string, error)
- func (l *Loader) GetLoaded() map[string]*LoadedPlugin
- func (l *Loader) GetPluginDir() string
- func (l *Loader) Index(ctx context.Context, fresh bool) ([]IndexEntry, error)
- func (l *Loader) Install(ctx context.Context, name string) error
- func (l *Loader) InstallAndLoad(ctx context.Context, name string) error
- func (l *Loader) InstallFileAndLoad(ctx context.Context, src string) error
- func (l *Loader) IsLoaded(name string) bool
- func (l *Loader) Load(ctx context.Context, path string) error
- func (l *Loader) LoadAll(ctx context.Context) error
- func (l *Loader) LoadByName(ctx context.Context, name string) error
- func (l *Loader) LoadedNames() []string
- func (l *Loader) Reload(ctx context.Context, name string) error
- func (l *Loader) Remove(ctx context.Context, name string) error
- func (l *Loader) RepoURL() string
- func (l *Loader) SetRepoURL(url string)
- func (l *Loader) Unload(ctx context.Context, name string) error
- type NameMismatchError
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*Loader) Failed ¶ added in v0.1.1
Failed returns plugin files in the directory that did not load, with the reason.
func (*Loader) GetAvailable ¶
GetAvailable returns .so files in the plugins dir that are NOT loaded.
func (*Loader) GetInstalled ¶
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 ¶
GetPluginDir returns the plugin directory path.
func (*Loader) Index ¶ added in v0.1.1
Index fetches the repository index, sorted by name. A fetch within the last minute is reused unless fresh is set.
func (*Loader) InstallAndLoad ¶ added in v0.1.1
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
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) LoadAll ¶
LoadAll loads all .so plugins from the plugins directory. Files that fail are remembered (see Failed) instead of aborting the rest.
func (*Loader) LoadByName ¶
LoadByName loads a plugin by name from the plugins directory.
func (*Loader) LoadedNames ¶ added in v0.1.1
LoadedNames returns the loaded plugin names, sorted.
func (*Loader) Reload ¶ added in v0.1.1
Reload unloads and loads one plugin again, re-reading its settings.
func (*Loader) Remove ¶
Remove unloads a plugin and deletes its .so file. Its settings stay in data/<name>/ so a reinstall picks them up again.
func (*Loader) SetRepoURL ¶
SetRepoURL sets the plugin registry URL.
type NameMismatchError ¶ added in v0.1.3
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