mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
perf: 移除插件系统冗余适配器层
优化内容: 1. 删除servicePluginAdapter适配器 - 移除无意义的类型转换层 - 插件直接注册到统一系统 2. 删除webPluginAdapter适配器 - 消除中间转发调用 - 简化Web插件注册流程 3. 删除localPluginAdapter适配器 - 移除多余的包装层 - 统一插件调用路径 性能提升: - 消除每次插件调用的中间层开销 - 减少函数调用栈深度 - 删除18行无用适配器代码 功能保持: - 用户参数调用插件功能完全保持 - 智能端口匹配逻辑不受影响 - 所有扫描功能正常工作
This commit is contained in:
parent
95497da8ca
commit
888a3d8d34
@ -20,8 +20,7 @@ type ScanResult = plugins.Result
|
|||||||
// 向后兼容的函数
|
// 向后兼容的函数
|
||||||
func RegisterLocalPlugin(name string, creator func() Plugin) {
|
func RegisterLocalPlugin(name string, creator func() Plugin) {
|
||||||
plugins.Register(name, func() plugins.Plugin {
|
plugins.Register(name, func() plugins.Plugin {
|
||||||
localPlugin := creator()
|
return creator()
|
||||||
return &localPluginAdapter{localPlugin}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,18 +32,6 @@ func GetAllLocalPlugins() []string {
|
|||||||
// 注意:GetLocalPlugin函数已移除,因为它总是返回nil没有任何意义
|
// 注意:GetLocalPlugin函数已移除,因为它总是返回nil没有任何意义
|
||||||
// 如需获取插件实例,请直接使用 plugins.Get(name)
|
// 如需获取插件实例,请直接使用 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 {
|
func GetSystemInfo() string {
|
||||||
|
@ -21,7 +21,7 @@ type Credential = plugins.Credential
|
|||||||
// RegisterPluginWithPorts 高效注册:直接传递端口信息,避免实例创建
|
// RegisterPluginWithPorts 高效注册:直接传递端口信息,避免实例创建
|
||||||
func RegisterPluginWithPorts(name string, factory func() Plugin, ports []int) {
|
func RegisterPluginWithPorts(name string, factory func() Plugin, ports []int) {
|
||||||
plugins.RegisterWithPorts(name, func() plugins.Plugin {
|
plugins.RegisterWithPorts(name, func() plugins.Plugin {
|
||||||
return &servicePluginAdapter{factory()}
|
return factory()
|
||||||
}, ports)
|
}, ports)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,15 +36,3 @@ func GetAllPlugins() []string {
|
|||||||
|
|
||||||
var GenerateCredentials = plugins.GenerateCredentials
|
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)
|
|
||||||
}
|
|
@ -18,7 +18,7 @@ type WebScanResult = plugins.Result
|
|||||||
// 向后兼容的函数
|
// 向后兼容的函数
|
||||||
func RegisterWebPlugin(name string, creator func() WebPlugin) {
|
func RegisterWebPlugin(name string, creator func() WebPlugin) {
|
||||||
plugins.Register(name, func() plugins.Plugin {
|
plugins.Register(name, func() plugins.Plugin {
|
||||||
return &webPluginAdapter{creator()}
|
return creator()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,15 +26,3 @@ func GetAllWebPlugins() []string {
|
|||||||
return plugins.All()
|
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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user