plugin

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LifecycleActivate   = "Activate"
	LifecycleDeactivate = "Deactivate"
	LifecycleUninstall  = "Uninstall"
)

Variables

This section is empty.

Functions

func OptionKey

func OptionKey(pluginID, optionID string) string

OptionKey 返回插件全局 option 在 Setting 表中的 key。

Types

type AssetDecl

type AssetDecl struct {
	Dir string `yaml:"dir" json:"dir"`
}

AssetDecl 描述插件静态资源目录。

type FunctionsScript

type FunctionsScript struct {
	PluginID string
	// contains filtered or unexported fields
}

FunctionsScript 表示一个已编译的插件 functions 脚本。

func CompileFunctions

func CompileFunctions(ctx context.Context, p *Plugin, hooks hook.Registry, log *slog.Logger) (*FunctionsScript, error)

CompileFunctions 编译插件目录下的 functions.go 或 functions.goyaegi 文件。 如果插件没有 functions 文件,返回 nil, nil。

func (*FunctionsScript) CallLifecycle

func (s *FunctionsScript) CallLifecycle(ctx context.Context, name string) error

CallLifecycle 调用插件 functions 中可选的生命周期函数。 支持 Activate/Deactivate/Uninstall 这类签名:func(api *hook.API) error。

type HookDecl

type HookDecl struct {
	Actions []string `yaml:"actions" json:"actions"`
	Filters []string `yaml:"filters" json:"filters"`
}

HookDecl 描述插件声明会使用的标准 action/filter。 该声明主要用于后台展示和能力说明,实际注册以 functions.goyaegi 为准。

type LifecycleDecl

type LifecycleDecl struct {
	Activate   bool `yaml:"activate" json:"activate"`
	Deactivate bool `yaml:"deactivate" json:"deactivate"`
	Uninstall  bool `yaml:"uninstall" json:"uninstall"`
}

LifecycleDecl 描述插件脚本实现的生命周期入口。 该声明用于后台展示和能力说明,实际调用仍以 functions.goyaegi 中的函数为准。

type Manager

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

Manager 管理插件扫描、启用列表和共享 Hook Registry。

func NewManager

func NewManager(pluginsDir string, store hook.SettingStore) (*Manager, error)

NewManager 创建插件管理器。pluginsDir 是插件存放目录(如 "plugins")。

func (*Manager) CallLifecycle

func (m *Manager) CallLifecycle(ctx context.Context, id, name string) error

CallLifecycle 调用插件 functions 中可选的生命周期函数。 启用中的插件优先复用已编译脚本;未启用插件则临时编译一份,只执行生命周期,不污染当前 Hook Registry。

func (*Manager) Delete

func (m *Manager) Delete(id string) error

Delete 删除指定插件目录并从内存中移除。

func (*Manager) Disable

func (m *Manager) Disable(ctx context.Context, id string) error

Disable 停用指定插件并持久化。

func (*Manager) Enable

func (m *Manager) Enable(ctx context.Context, id string) error

Enable 启用指定插件并持久化。

func (*Manager) Enabled

func (m *Manager) Enabled(ctx context.Context) []*Plugin

Enabled 返回当前启用且已安装的插件列表,顺序与设置中保存的一致。

func (*Manager) EnabledIDs

func (m *Manager) EnabledIDs(ctx context.Context) []string

EnabledIDs 返回当前持久化启用的插件 ID 列表。

func (*Manager) EnabledWidgetDecls

func (m *Manager) EnabledWidgetDecls(ctx context.Context) []WidgetDecl

EnabledWidgetDecls 返回当前所有已启用插件声明的小组件。

func (*Manager) Get

func (m *Manager) Get(id string) *Plugin

Get 按 ID 获取插件,不存在返回 nil。

func (*Manager) GetRegistry

func (m *Manager) GetRegistry() hook.Registry

GetRegistry 返回插件系统共享的 Hook Registry(实例稳定,不会因重载而替换)。

func (*Manager) Install

func (m *Manager) Install(dir string) (*Plugin, error)

Install 从已解压的目录安装插件。dir 是插件根目录(含 plugin.yaml)。

func (*Manager) List

func (m *Manager) List() []*Plugin

List 返回所有已安装插件列表,按 ID 排序。

func (*Manager) LoadEnabledFunctions

func (m *Manager) LoadEnabledFunctions(ctx context.Context) error

LoadEnabledFunctions 按启用顺序编译插件 functions,成功后原子替换到共享 Registry。 编译到临时 Registry 中,失败时不影响当前已加载的处理器。

func (*Manager) LoadErrors

func (m *Manager) LoadErrors() map[string]string

LoadErrors 返回最近一次插件运行时加载错误快照,key 为插件 ID。

func (*Manager) LoadTranslations

func (m *Manager) LoadTranslations() error

LoadTranslations 加载所有已安装插件自带的翻译文件。

func (*Manager) PluginsDir

func (m *Manager) PluginsDir() string

PluginsDir 返回插件存放目录路径。

func (*Manager) RebuildTranslations

func (m *Manager) RebuildTranslations() error

RebuildTranslations 重新构建应用域和所有插件域的翻译映射。

func (*Manager) RegisterPluginWidgets

func (m *Manager) RegisterPluginWidgets(ctx context.Context, widgetRegistry *hook.WidgetRegistry)

RegisterPluginWidgets 将已启用插件的组件注册到组件注册表。

func (*Manager) RenderWidget

func (m *Manager) RenderWidget(ctx context.Context, pluginID, widgetID string, options map[string]string, data any) (template.HTML, bool)

RenderWidget 渲染插件组件。插件组件由 manifest 声明并注册为明确的 Widget renderer, 渲染时执行插件 widgets/<id>.gohtml 模板。

func (*Manager) Uninstall

func (m *Manager) Uninstall(ctx context.Context, id string) error

Uninstall 执行插件卸载生命周期、从启用列表移除并删除插件目录。

type OptionDecl

type OptionDecl = hook.OptionDecl

以下类型别名指向 hook 包,避免各包重复定义。

type Plugin

type Plugin struct {
	ID          string `yaml:"id" json:"id"`
	Name        string `yaml:"name" json:"name"`
	Version     string `yaml:"version" json:"version"`
	Description string `yaml:"description" json:"description"`
	Author      string `yaml:"author" json:"author"`
	// DefaultEnabled 表示尚未保存启用列表时是否默认启用该插件。
	DefaultEnabled bool              `yaml:"default_enabled" json:"default_enabled"`
	Dir            string            `yaml:"-" json:"-"`
	Hooks          HookDecl          `yaml:"hooks" json:"hooks"`
	Lifecycle      LifecycleDecl     `yaml:"lifecycle" json:"lifecycle"`
	Widgets        []WidgetDecl      `yaml:"widgets" json:"widgets"`
	Options        []hook.OptionDecl `yaml:"options" json:"options"`
	Assets         AssetDecl         `yaml:"assets" json:"assets"`
}

Plugin 表示一个已安装插件的 manifest 信息。

func LoadPlugin

func LoadPlugin(dir string) (*Plugin, error)

LoadPlugin 从目录加载 plugin.yaml 并返回 Plugin。

func (*Plugin) AssetsDir

func (p *Plugin) AssetsDir() string

AssetsDir 返回插件静态资源目录路径。

func (*Plugin) FunctionsPath

func (p *Plugin) FunctionsPath() string

FunctionsPath 返回插件 functions 脚本路径。

func (*Plugin) HasAssets

func (p *Plugin) HasAssets() bool

HasAssets 检查插件是否包含静态资源目录。

func (*Plugin) I18nDir

func (p *Plugin) I18nDir() string

I18nDir 返回插件自带翻译文件目录路径。

func (*Plugin) LoadTranslations

func (p *Plugin) LoadTranslations() error

LoadTranslations 把插件 i18n 目录绑定到插件 ID 对应的文本域。

func (*Plugin) PluginDomain

func (p *Plugin) PluginDomain() string

PluginDomain 返回插件翻译使用的文本域名。

func (*Plugin) TemplatesDir

func (p *Plugin) TemplatesDir() string

TemplatesDir 返回插件模板目录路径。

func (*Plugin) WidgetsDir

func (p *Plugin) WidgetsDir() string

WidgetsDir 返回插件组件模板目录路径。

type SelectOpt

type SelectOpt = hook.SelectOpt

type WidgetDecl

type WidgetDecl = hook.WidgetDecl

WidgetDecl 是 hook.WidgetDecl 的别名,描述插件提供的一类组件。

Jump to

Keyboard shortcuts

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