From fb70a53705237099f4224fb91f9babca04a28b9c Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 2 Apr 2023 16:53:24 +0800 Subject: [PATCH] [fix] plugins load --- cmd/start.go | 12 ++++++------ engine/load.go | 1 + model/model.go | 14 +++++++++++++- plugin/plugin.go | 15 +++++++++++++-- store/store.go | 15 +++++++++++++-- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index bd25a2f6..18e44098 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -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) } diff --git a/engine/load.go b/engine/load.go index 5ba4ff33..18e17e06 100644 --- a/engine/load.go +++ b/engine/load.go @@ -34,6 +34,7 @@ import ( // Load application engine func Load(cfg config.Config) (err error) { + defer func() { err = exception.Catch(recover()) }() // SET XGEN_BASE diff --git a/model/model.go b/model/model.go index 4a8d2569..a15cbaa9 100644 --- a/model/model.go +++ b/model/model.go @@ -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 } diff --git a/plugin/plugin.go b/plugin/plugin.go index 511bdc25..7437daa8 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -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 diff --git a/store/store.go b/store/store.go index 35ae8313..267fa2f7 100644 --- a/store/store.go +++ b/store/store.go @@ -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 }