Documentation
¶
Index ¶
- Constants
- func OptionKey(pluginID, optionID string) string
- type AssetDecl
- type FunctionsScript
- type HookDecl
- type LifecycleDecl
- type Manager
- func (m *Manager) CallLifecycle(ctx context.Context, id, name string) error
- func (m *Manager) Delete(id string) error
- func (m *Manager) Disable(ctx context.Context, id string) error
- func (m *Manager) Enable(ctx context.Context, id string) error
- func (m *Manager) Enabled(ctx context.Context) []*Plugin
- func (m *Manager) EnabledIDs(ctx context.Context) []string
- func (m *Manager) EnabledWidgetDecls(ctx context.Context) []WidgetDecl
- func (m *Manager) Get(id string) *Plugin
- func (m *Manager) GetRegistry() hook.Registry
- func (m *Manager) Install(dir string) (*Plugin, error)
- func (m *Manager) List() []*Plugin
- func (m *Manager) LoadEnabledFunctions(ctx context.Context) error
- func (m *Manager) LoadErrors() map[string]string
- func (m *Manager) LoadTranslations() error
- func (m *Manager) PluginsDir() string
- func (m *Manager) RebuildTranslations() error
- func (m *Manager) RegisterPluginWidgets(ctx context.Context, widgetRegistry *hook.WidgetRegistry)
- func (m *Manager) RenderWidget(ctx context.Context, pluginID, widgetID string, options map[string]string, ...) (template.HTML, bool)
- func (m *Manager) Uninstall(ctx context.Context, id string) error
- type OptionDecl
- type Plugin
- func (p *Plugin) AssetsDir() string
- func (p *Plugin) FunctionsPath() string
- func (p *Plugin) HasAssets() bool
- func (p *Plugin) I18nDir() string
- func (p *Plugin) LoadTranslations() error
- func (p *Plugin) PluginDomain() string
- func (p *Plugin) TemplatesDir() string
- func (p *Plugin) WidgetsDir() string
- type SelectOpt
- type WidgetDecl
Constants ¶
const ( LifecycleActivate = "Activate" LifecycleDeactivate = "Deactivate" LifecycleUninstall = "Uninstall" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 ¶
CallLifecycle 调用插件 functions 中可选的生命周期函数。 启用中的插件优先复用已编译脚本;未启用插件则临时编译一份,只执行生命周期,不污染当前 Hook Registry。
func (*Manager) EnabledIDs ¶
EnabledIDs 返回当前持久化启用的插件 ID 列表。
func (*Manager) EnabledWidgetDecls ¶
func (m *Manager) EnabledWidgetDecls(ctx context.Context) []WidgetDecl
EnabledWidgetDecls 返回当前所有已启用插件声明的小组件。
func (*Manager) GetRegistry ¶
GetRegistry 返回插件系统共享的 Hook Registry(实例稳定,不会因重载而替换)。
func (*Manager) LoadEnabledFunctions ¶
LoadEnabledFunctions 按启用顺序编译插件 functions,成功后原子替换到共享 Registry。 编译到临时 Registry 中,失败时不影响当前已加载的处理器。
func (*Manager) LoadErrors ¶
LoadErrors 返回最近一次插件运行时加载错误快照,key 为插件 ID。
func (*Manager) LoadTranslations ¶
LoadTranslations 加载所有已安装插件自带的翻译文件。
func (*Manager) RebuildTranslations ¶
RebuildTranslations 重新构建应用域和所有插件域的翻译映射。
func (*Manager) RegisterPluginWidgets ¶
func (m *Manager) RegisterPluginWidgets(ctx context.Context, widgetRegistry *hook.WidgetRegistry)
RegisterPluginWidgets 将已启用插件的组件注册到组件注册表。
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 ¶
LoadPlugin 从目录加载 plugin.yaml 并返回 Plugin。
func (*Plugin) FunctionsPath ¶
FunctionsPath 返回插件 functions 脚本路径。
func (*Plugin) LoadTranslations ¶
LoadTranslations 把插件 i18n 目录绑定到插件 ID 对应的文本域。