1 Star 0 Fork 0

jack/hi-things

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
plugin_manager.go 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
jack 提交于 2024-11-11 11:18 . 初始化
package plugins
import (
"gitee.com/wujianhai/hi-things/config"
"github.com/asynkron/protoactor-go/actor"
"log"
"os"
"path/filepath"
"strings"
)
// 内置插件管理器
type BuildInPluginManager struct {
System *actor.ActorSystem
Plugins []Plugin
}
func (m *BuildInPluginManager) loadPlugins() error {
m.System.Logger().Info("loading build-in plugins")
return nil
}
func NewBuildInPluginManager(system *actor.ActorSystem) *BuildInPluginManager {
globalFilePath := config.GetGlobalPath()
filepath.WalkDir(globalFilePath.LibPath, func(path string, d os.DirEntry, err error) error {
return nil
})
return &BuildInPluginManager{System: system}
}
// 扩展插件管理器
type ExtPluginManager struct {
System *actor.ActorSystem
Plugins []Plugin
}
func (m *ExtPluginManager) loadPlugins() error {
m.System.Logger().Info("loading extension plugins")
return nil
}
func NewExtPluginManager(system *actor.ActorSystem) *ExtPluginManager {
globalFilePath := config.GetGlobalPath()
filepath.WalkDir(globalFilePath.PluginPath, func(path string, d os.DirEntry, err error) error {
return err
})
return &ExtPluginManager{System: system}
}
type PluginManager struct {
BuildInPluginManager *BuildInPluginManager
ExtPluginManager *ExtPluginManager
}
func (m *PluginManager) LoadPlugins() error {
log.Println("loading plugins...")
buildErr := m.BuildInPluginManager.loadPlugins()
if buildErr != nil {
m.BuildInPluginManager.System.Logger().Error("loading build-in plugins failure", "err", buildErr)
return buildErr
}
extLoadErr := m.ExtPluginManager.loadPlugins()
if extLoadErr != nil {
m.BuildInPluginManager.System.Logger().Error("loading extension plugins failure", "err", extLoadErr)
return extLoadErr
}
return nil
}
func NewPluginManager(system *actor.ActorSystem) *PluginManager {
return &PluginManager{
BuildInPluginManager: NewBuildInPluginManager(system),
ExtPluginManager: NewExtPluginManager(system),
}
}
func discoverPlugins(pluginDir string) ([]string, error) {
var plugins []string
files, err := os.ReadDir(pluginDir)
if err != nil {
return nil, err
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".so") {
plugins = append(plugins, filepath.Join(pluginDir, file.Name()))
}
}
return plugins, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wujianhai/hi-things.git
git@gitee.com:wujianhai/hi-things.git
wujianhai
hi-things
hi-things
4f7e2d9fb30f

搜索帮助