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) 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
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") )
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.
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.