forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
package flow | ||
|
||
// Load 加载业务逻辑编排 | ||
func Load(filepath string) {} | ||
import ( | ||
"fmt" | ||
|
||
"github.com/yaoapp/gou" | ||
"github.com/yaoapp/xiang/config" | ||
"github.com/yaoapp/xiang/share" | ||
) | ||
|
||
// Load 加载API | ||
func Load(cfg config.Config) { | ||
fmt.Println(cfg.RootFLow) | ||
LoadFrom(cfg.RootFLow, "") | ||
} | ||
|
||
// LoadFrom 从特定目录加载 | ||
func LoadFrom(dir string, prefix string) { | ||
|
||
if share.DirNotExists(dir) { | ||
return | ||
} | ||
|
||
share.Walk(dir, ".json", func(root, filename string) { | ||
name := share.SpecName(root, filename) | ||
content := share.ReadFile(filename) | ||
gou.LoadFlow(string(content), prefix+name) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package flow | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-playground/assert/v2" | ||
"github.com/yaoapp/gou" | ||
"github.com/yaoapp/xiang/config" | ||
) | ||
|
||
func TestLoad(t *testing.T) { | ||
gou.Flows = make(map[string]*gou.Flow) | ||
Load(config.Conf) | ||
LoadFrom("not a path", "404.") | ||
check(t) | ||
} | ||
|
||
func check(t *testing.T) { | ||
keys := []string{} | ||
for key := range gou.Flows { | ||
keys = append(keys, key) | ||
} | ||
assert.Equal(t, 2, len(keys)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"label": "最新信息", | ||
"version": "1.0.0", | ||
"description": "最新信息", | ||
"nodes": [ | ||
{ | ||
"name": "user", | ||
"engine": "xiang", | ||
"query": { | ||
"select": ["id", "name"], | ||
"from": "$user", | ||
"first": true | ||
} | ||
} | ||
], | ||
"output": { | ||
"params": "{{$in}}" | ||
} | ||
} |