Skip to content

Commit

Permalink
优化热加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 20, 2021
1 parent 2779e79 commit 490a1c9
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 340 deletions.
11 changes: 5 additions & 6 deletions chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ func LoadFrom(dir string, prefix string) {
share.Walk(dir, ".json", func(root, filename string) {
name := share.SpecName(root, filename)
content := share.ReadFile(filename)
chart, err := LoadChart(content, name)
_, err := LoadChart(content, name)
if err != nil {
exception.New("%s 图表格式错误", 400, name).Ctx(filename).Throw()
}
Charts[name] = chart
})
}

// LoadChart 载入数据表格
func LoadChart(source []byte, name string) (*Chart, error) {
chart := Chart{
chart := &Chart{
Flow: gou.Flow{
Name: name,
},
}
err := jsoniter.Unmarshal(source, &chart)
err := jsoniter.Unmarshal(source, chart)
if err != nil {
xlog.Println(name)
xlog.Println(err.Error())
Expand All @@ -53,8 +52,8 @@ func LoadChart(source []byte, name string) (*Chart, error) {
}
chart.Prepare()
chart.SetupAPIs()

return &chart, nil
Charts[name] = chart
return chart, nil
}

// Select 读取已加载图表
Expand Down
2 changes: 1 addition & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var startCmd = &cobra.Command{

// 调试模式
if config.Conf.Mode == "debug" {
service.WatchChanges()
service.Watch(config.Conf)
}

service.Start()
Expand Down
4 changes: 2 additions & 2 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

// Load 加载业务插件
func Load(cfg config.Config) {
LoadFrom(cfg.RootPlugin, "")
LoadFrom(cfg.RootPlugin)
}

// LoadFrom 从特定目录加载
func LoadFrom(dir string, prefix string) {
func LoadFrom(dir string) {

if share.DirNotExists(dir) {
return
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestLoad(t *testing.T) {
gou.Plugins = make(map[string]*gou.Plugin)
Load(config.Conf)
LoadFrom("not a path", "404.")
LoadFrom("404")
check(t)
}

Expand Down
Loading

0 comments on commit 490a1c9

Please sign in to comment.