[add] Store Process & Javascript Object
This commit is contained in:
parent
79dd564803
commit
44c041decf
4 changed files with 73 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/yaoapp/yao/script"
|
||||
"github.com/yaoapp/yao/server"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/store"
|
||||
"github.com/yaoapp/yao/table"
|
||||
"github.com/yaoapp/yao/workflow"
|
||||
)
|
||||
|
|
@ -56,6 +57,7 @@ func Load(cfg config.Config) (err error) {
|
|||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
err = script.Load(cfg) // 加载JS处理器 script
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
|
|
@ -71,6 +73,12 @@ func Load(cfg config.Config) (err error) {
|
|||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
err = store.Load(cfg) // Load stores
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
err = plugin.Load(cfg) // 加载业务插件 plugin
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
|
|
|
|||
36
store/store.go
Normal file
36
store/store.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load load store
|
||||
func Load(cfg config.Config) error {
|
||||
var root = filepath.Join(cfg.Root, "stores")
|
||||
return LoadFrom(root, "")
|
||||
}
|
||||
|
||||
// LoadFrom load from dir
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadStore(string(content), name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
23
store/store_test.go
Normal file
23
store/store_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou/kv"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range kv.Pools {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 1, len(keys))
|
||||
}
|
||||
6
tests/stores/share.lru.json
Normal file
6
tests/stores/share.lru.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Share LRU Cache",
|
||||
"description": "The share memory LRU cache",
|
||||
"type": "lru",
|
||||
"option": { "size": 1024 }
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue