Skip to content

Commit

Permalink
[fix] plugins load
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Apr 2, 2023
1 parent 0ff7fcc commit fb70a53
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
12 changes: 6 additions & 6 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
}()
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions engine/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

// Load application engine
func Load(cfg config.Config) (err error) {

defer func() { err = exception.Catch(recover()) }()

// SET XGEN_BASE
Expand Down
14 changes: 13 additions & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"
"strings"

"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/model"
Expand All @@ -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
}
15 changes: 13 additions & 2 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plugin

import (
"fmt"
"io/fs"
"path/filepath"
"strings"
Expand All @@ -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
}

Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package store

import (
"fmt"
"strings"

"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/store"
"github.com/yaoapp/yao/config"
Expand All @@ -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
}

0 comments on commit fb70a53

Please sign in to comment.