代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。