diff --git a/engine/load.go b/engine/load.go index 21a15959..9419e236 100644 --- a/engine/load.go +++ b/engine/load.go @@ -14,6 +14,7 @@ import ( "github.com/yaoapp/xiang/config" "github.com/yaoapp/xiang/flow" "github.com/yaoapp/xiang/model" + "github.com/yaoapp/xiang/plugin" "github.com/yaoapp/xiang/share" "github.com/yaoapp/xiang/table" ) @@ -26,9 +27,11 @@ func Load(cfg config.Config) { app.Load(cfg) // 加载应用信息 LoadEngine(cfg.Path) - model.Load(cfg) // 加载数据模型 - api.Load(cfg) // 加载API - flow.Load(cfg) // 加载Flow + model.Load(cfg) // 加载数据模型 model + api.Load(cfg) // 加载业务接口 API + flow.Load(cfg) // 加载业务逻辑 Flow + plugin.Load(cfg) // 加载业务插件 plugin + LoadApp(share.AppRoot{ APIs: cfg.RootAPI, Flows: cfg.RootFLow, @@ -169,13 +172,13 @@ func LoadApp(app share.AppRoot) { // } // 加载Plugin - if strings.HasPrefix(app.Plugins, "fs://") || !strings.Contains(app.Plugins, "://") { - root := strings.TrimPrefix(app.Plugins, "fs://") - scripts := share.GetAppPlugins(root, ".so") - for _, script := range scripts { - gou.LoadPlugin(script.File, script.Name) - } - } + // if strings.HasPrefix(app.Plugins, "fs://") || !strings.Contains(app.Plugins, "://") { + // root := strings.TrimPrefix(app.Plugins, "fs://") + // scripts := share.GetAppPlugins(root, ".so") + // for _, script := range scripts { + // gou.LoadPlugin(script.File, script.Name) + // } + // } // 加载Table if strings.HasPrefix(app.Tables, "fs://") || !strings.Contains(app.Tables, "://") { diff --git a/model/init_test.go b/model/init_test.go deleted file mode 100644 index 9af906af..00000000 --- a/model/init_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package model - -import ( - "os" - "testing" - - "github.com/yaoapp/gou" - "github.com/yaoapp/xiang/config" -) - -var cfg config.Config - -func TestMain(m *testing.M) { - - // Run test suites - exitVal := m.Run() - - // we can do clean up code here - gou.KillPlugins() - - os.Exit(exitVal) -} diff --git a/plugin/plugin.go b/plugin/plugin.go index 53d0557d..08adfeaf 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -1,4 +1,25 @@ package plugin -// Load 加载应用插件 -func Load(filepath string) {} +import ( + "github.com/yaoapp/gou" + "github.com/yaoapp/xiang/config" + "github.com/yaoapp/xiang/share" +) + +// Load 加载数据模型 +func Load(cfg config.Config) { + LoadFrom(cfg.RootPlugin, "") +} + +// LoadFrom 从特定目录加载 +func LoadFrom(dir string, prefix string) { + + if share.DirNotExists(dir) { + return + } + + share.Walk(dir, ".so", func(root, filename string) { + name := share.SpecName(root, filename) + gou.LoadPlugin(filename, name) + }) +} diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go new file mode 100644 index 00000000..61cac039 --- /dev/null +++ b/plugin/plugin_test.go @@ -0,0 +1,25 @@ +package plugin + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/yaoapp/gou" + "github.com/yaoapp/xiang/config" +) + +func TestLoad(t *testing.T) { + gou.Plugins = make(map[string]*gou.Plugin) + Load(config.Conf) + LoadFrom("not a path", "404.") + check(t) +} + +func check(t *testing.T) { + keys := []string{} + for key := range gou.Plugins { + keys = append(keys, key) + } + assert.Equal(t, 1, len(keys)) +}