优化载入逻辑: Step 4/5
This commit is contained in:
parent
9cffe860d8
commit
36bfeb8aad
4 changed files with 61 additions and 34 deletions
|
|
@ -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, "://") {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
25
plugin/plugin_test.go
Normal file
25
plugin/plugin_test.go
Normal file
|
|
@ -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))
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue