[fix] plugins load

This commit is contained in:
Max 2023-04-02 16:53:24 +08:00
parent 0ff7fccc55
commit fb70a53705
5 changed files with 46 additions and 11 deletions

View file

@ -70,7 +70,7 @@ var startCmd = &cobra.Command{
// load the application engine
err := engine.Load(config.Conf)
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
fmt.Println(color.RedString(L("Load: %s"), err.Error()))
os.Exit(1)
}
@ -82,7 +82,7 @@ var startCmd = &cobra.Command{
// variables for the service
fs, err := fs.Get("system")
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
fmt.Println(color.RedString(L("FileSystem: %s"), err.Error()))
os.Exit(1)
}
@ -121,7 +121,7 @@ var startCmd = &cobra.Command{
go func() {
err := studio.Start(config.Conf)
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
fmt.Println(color.RedString(L("Studio: %s"), err.Error()))
os.Exit(2)
}
}()
@ -159,9 +159,9 @@ var startCmd = &cobra.Command{
// Start watching
watchDone := make(chan uint8, 1)
if mode == "development" && !startDisableWatching {
fmt.Println(color.WhiteString("\n---------------------------------"))
fmt.Println(color.WhiteString(L("Watching")))
fmt.Println(color.WhiteString("---------------------------------"))
// fmt.Println(color.WhiteString("\n---------------------------------"))
// fmt.Println(color.WhiteString(L("Watching")))
// fmt.Println(color.WhiteString("---------------------------------"))
go service.Watch(srv, watchDone)
}

View file

@ -34,6 +34,7 @@ import (
// Load application engine
func Load(cfg config.Config) (err error) {
defer func() { err = exception.Catch(recover()) }()
// SET XGEN_BASE

View file

@ -2,6 +2,7 @@ package model
import (
"fmt"
"strings"
"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/model"
@ -12,15 +13,26 @@ import (
// Load 加载数据模型
func Load(cfg config.Config) error {
messages := []string{}
model.WithCrypt([]byte(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey)), "AES")
model.WithCrypt([]byte(`{}`), "PASSWORD")
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
return application.App.Walk("models", func(root, file string, isdir bool) error {
err := application.App.Walk("models", func(root, file string, isdir bool) error {
if isdir {
return nil
}
_, err := model.Load(file, share.ID(root, file))
if err != nil {
messages = append(messages, err.Error())
}
return err
}, exts...)
if len(messages) > 0 {
return fmt.Errorf(strings.Join(messages, ";\n"))
}
return err
}

View file

@ -1,6 +1,7 @@
package plugin
import (
"fmt"
"io/fs"
"path/filepath"
"strings"
@ -18,8 +19,9 @@ func Load(cfg config.Config) error {
return err
}
return filepath.Walk(root, func(file string, info fs.FileInfo, err error) error {
if info.IsDir() {
messages := []string{}
err = filepath.Walk(root, func(file string, info fs.FileInfo, err error) error {
if info == nil || info.IsDir() {
return nil
}
@ -28,9 +30,18 @@ func Load(cfg config.Config) error {
}
_, err = plugin.Load(file, share.ID(root, file))
if err != nil {
messages = append(messages, err.Error())
}
return err
})
if len(messages) > 0 {
return fmt.Errorf(strings.Join(messages, ";\n"))
}
return err
}
// Root return plugin root

View file

@ -1,6 +1,9 @@
package store
import (
"fmt"
"strings"
"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/store"
"github.com/yaoapp/yao/config"
@ -9,13 +12,21 @@ import (
// Load load store
func Load(cfg config.Config) error {
messages := []string{}
exts := []string{"*.yao", "*.json", "*.jsonc"}
return application.App.Walk("stores", func(root, file string, isdir bool) error {
err := application.App.Walk("stores", func(root, file string, isdir bool) error {
if isdir {
return nil
}
_, err := store.Load(file, share.ID(root, file))
if err != nil {
messages = append(messages, err.Error())
}
return err
}, exts...)
if len(messages) > 0 {
return fmt.Errorf(strings.Join(messages, ";\n"))
}
return err
}