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

View file

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

View file

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

View file

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

View file

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