增强插件系统:添加插件类型支持

- 在插件接口和基本插件结构中引入插件类型(PluginType),并定义了多种预定义的插件类型。
- 更新插件管理器以支持按类型管理插件,新增按类型获取、初始化和启动插件的方法。
- 修改现有插件(如日志插件和统计插件)以实现插件类型接口,确保兼容性。
- 优化插件信息输出,包含插件类型信息。

此更新提升了插件系统的灵活性和可扩展性,便于未来添加更多插件类型。
This commit is contained in:
2025-03-14 11:07:53 +08:00
parent d423ed5029
commit 098c721ee9
8 changed files with 469 additions and 13 deletions

View File

@@ -1,5 +1,19 @@
package plugin
// PluginType 插件类型
type PluginType string
// 预定义的插件类型
const (
PluginTypeGeneral PluginType = "general" // 通用插件
PluginTypeStorage PluginType = "storage" // 存储插件
PluginTypeSecurity PluginType = "security" // 安全插件
PluginTypeUI PluginType = "ui" // 用户界面插件
PluginTypeNetwork PluginType = "network" // 网络插件
PluginTypeUtils PluginType = "utils" // 工具插件
// 可以根据需求添加更多插件类型
)
// IPlugin 插件接口
// 这个文件定义了所有插件必须实现的接口
// 注意:这个文件应该与实际插件代码一起编译
@@ -12,6 +26,8 @@ type IPlugin interface {
Description() string
// Author 插件作者
Author() string
// Type 插件类型
Type() PluginType
// Init 初始化插件
Init(config map[string]interface{}) error
// Start 启动插件
@@ -31,16 +47,18 @@ type BasePlugin struct {
version string
description string
author string
pluginType PluginType
enabled bool
}
// NewBasePlugin 创建一个基本插件
func NewBasePlugin(name, version, description, author string) *BasePlugin {
func NewBasePlugin(name, version, description, author string, pluginType PluginType) *BasePlugin {
return &BasePlugin{
name: name,
version: version,
description: description,
author: author,
pluginType: pluginType,
enabled: true,
}
}
@@ -65,6 +83,11 @@ func (p *BasePlugin) Author() string {
return p.author
}
// Type 获取插件类型
func (p *BasePlugin) Type() PluginType {
return p.pluginType
}
// IsEnabled 插件是否启用
func (p *BasePlugin) IsEnabled() bool {
return p.enabled