Skip to content

Commit

Permalink
优化载入逻辑: Step 4/5
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 18, 2021
1 parent 9cffe86 commit 36bfeb8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
23 changes: 13 additions & 10 deletions engine/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down Expand Up @@ -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, "://") {
Expand Down
22 changes: 0 additions & 22 deletions model/init_test.go

This file was deleted.

25 changes: 23 additions & 2 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 36bfeb8

Please sign in to comment.