perf: 移除插件系统冗余适配器层

优化内容:
1. 删除servicePluginAdapter适配器
   - 移除无意义的类型转换层
   - 插件直接注册到统一系统

2. 删除webPluginAdapter适配器
   - 消除中间转发调用
   - 简化Web插件注册流程

3. 删除localPluginAdapter适配器
   - 移除多余的包装层
   - 统一插件调用路径

性能提升:
- 消除每次插件调用的中间层开销
- 减少函数调用栈深度
- 删除18行无用适配器代码

功能保持:
- 用户参数调用插件功能完全保持
- 智能端口匹配逻辑不受影响
- 所有扫描功能正常工作
This commit is contained in:
ZacharyZcR 2025-09-02 06:27:14 +08:00
parent 95497da8ca
commit 888a3d8d34
3 changed files with 3 additions and 40 deletions

View File

@ -20,8 +20,7 @@ type ScanResult = plugins.Result
// 向后兼容的函数
func RegisterLocalPlugin(name string, creator func() Plugin) {
plugins.Register(name, func() plugins.Plugin {
localPlugin := creator()
return &localPluginAdapter{localPlugin}
return creator()
})
}
@ -33,18 +32,6 @@ func GetAllLocalPlugins() []string {
// 注意GetLocalPlugin函数已移除因为它总是返回nil没有任何意义
// 如需获取插件实例,请直接使用 plugins.Get(name)
// 适配器将Local插件转换为统一插件接口
type localPluginAdapter struct {
localPlugin Plugin
}
func (a *localPluginAdapter) Name() string {
return a.localPlugin.Name()
}
func (a *localPluginAdapter) Scan(ctx context.Context, info *common.HostInfo) *plugins.Result {
return a.localPlugin.Scan(ctx, info)
}
// 保留的工具函数
func GetSystemInfo() string {

View File

@ -21,7 +21,7 @@ type Credential = plugins.Credential
// RegisterPluginWithPorts 高效注册:直接传递端口信息,避免实例创建
func RegisterPluginWithPorts(name string, factory func() Plugin, ports []int) {
plugins.RegisterWithPorts(name, func() plugins.Plugin {
return &servicePluginAdapter{factory()}
return factory()
}, ports)
}
@ -36,15 +36,3 @@ func GetAllPlugins() []string {
var GenerateCredentials = plugins.GenerateCredentials
// 适配器将services插件转换为统一插件接口
type servicePluginAdapter struct {
servicePlugin Plugin
}
func (a *servicePluginAdapter) Name() string {
return a.servicePlugin.Name()
}
func (a *servicePluginAdapter) Scan(ctx context.Context, info *common.HostInfo) *plugins.Result {
return a.servicePlugin.Scan(ctx, info)
}

View File

@ -18,7 +18,7 @@ type WebScanResult = plugins.Result
// 向后兼容的函数
func RegisterWebPlugin(name string, creator func() WebPlugin) {
plugins.Register(name, func() plugins.Plugin {
return &webPluginAdapter{creator()}
return creator()
})
}
@ -26,15 +26,3 @@ func GetAllWebPlugins() []string {
return plugins.All()
}
// 适配器将Web插件转换为统一插件接口
type webPluginAdapter struct {
webPlugin WebPlugin
}
func (a *webPluginAdapter) Name() string {
return a.webPlugin.Name()
}
func (a *webPluginAdapter) Scan(ctx context.Context, info *common.HostInfo) *plugins.Result {
return a.webPlugin.Scan(ctx, info)
}