[*] migrate to gou v0.10.3 (50%)
This commit is contained in:
parent
8d40c8e70c
commit
a807899f95
224 changed files with 1617 additions and 6593 deletions
59
api/api.go
59
api/api.go
|
|
@ -1,60 +1,17 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/gou/api"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load 加载API
|
||||
// Load apis
|
||||
func Load(cfg config.Config) error {
|
||||
if share.BUILDIN {
|
||||
return LoadBuildIn("apis", "")
|
||||
}
|
||||
return LoadFrom(filepath.Join(cfg.Root, "apis"), "")
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
messages := []string{}
|
||||
err := share.Walk(dir, ".http.json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadAPIReturn(string(content), name, "bearer-jwt")
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
messages = append(messages, fmt.Sprintf("%s %s", name, err.Error()))
|
||||
}
|
||||
})
|
||||
|
||||
// Load WebSocket Server
|
||||
err = share.Walk(dir, ".ws.json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadWebSocketServer(string(content), name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
messages = append(messages, fmt.Sprintf("%s %s", name, err.Error()))
|
||||
}
|
||||
})
|
||||
|
||||
if len(messages) > 0 {
|
||||
return fmt.Errorf("%s", strings.Join(messages, ";"))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// LoadBuildIn 从制品中读取
|
||||
func LoadBuildIn(dir string, prefix string) error {
|
||||
return nil
|
||||
exts := []string{"*.http.yao", "*.http.json", "*.http.jsonc"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
_, err := api.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,19 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/api"
|
||||
"github.com/yaoapp/gou/websocket"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
gou.APIs = make(map[string]*gou.API)
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range gou.APIs {
|
||||
for key := range api.APIs {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
# 应用信息
|
||||
82
app/app.go
82
app/app.go
|
|
@ -1,82 +0,0 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
l "github.com/yaoapp/gou/lang"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/data"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/xfs"
|
||||
)
|
||||
|
||||
// Load Application
|
||||
func Load(cfg config.Config) {
|
||||
|
||||
// Set language pack
|
||||
share.App.L = map[string]string{}
|
||||
if l.Default != nil {
|
||||
share.App.L = l.Default.Global
|
||||
}
|
||||
|
||||
// Load Info
|
||||
LoadInfo(cfg.Root)
|
||||
|
||||
}
|
||||
|
||||
// L 语言包
|
||||
func L(word string) string {
|
||||
if trans, has := share.App.L[word]; has {
|
||||
return trans
|
||||
}
|
||||
return word
|
||||
}
|
||||
|
||||
// LoadInfo 应用信息
|
||||
func LoadInfo(root string) {
|
||||
info := defaultInfo()
|
||||
fs := xfs.New(root)
|
||||
if fs.MustExists("/app.json") {
|
||||
err := jsoniter.Unmarshal(fs.MustReadFile("/app.json"), &info)
|
||||
if err != nil {
|
||||
exception.New("解析应用失败 %s", 500, err).Throw()
|
||||
}
|
||||
}
|
||||
if has, _ := fs.Exists("/yao/icons/icon.icns"); has {
|
||||
info.Icons.Set("icns", xfs.Encode(fs.MustReadFile("/yao/icons/icon.icns")))
|
||||
}
|
||||
|
||||
if has, _ := fs.Exists("/yao/icons/icon.ico"); has {
|
||||
info.Icons.Set("ico", xfs.Encode(fs.MustReadFile("/yao/icons/icon.ico")))
|
||||
}
|
||||
|
||||
if has, _ := fs.Exists("/yao/icons/icon.png"); has {
|
||||
info.Icons.Set("png", xfs.Encode(fs.MustReadFile("/yao/icons/icon.png")))
|
||||
}
|
||||
|
||||
info.L = share.App.L
|
||||
share.App = info
|
||||
}
|
||||
|
||||
// LoadLangBuildIn 从制品中读取
|
||||
func LoadLangBuildIn(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// defaultInfo 读取默认应用信息
|
||||
func defaultInfo() share.AppInfo {
|
||||
info := share.AppInfo{
|
||||
Icons: maps.MakeSync(),
|
||||
}
|
||||
err := jsoniter.Unmarshal(data.MustAsset("yao/data/app.json"), &info)
|
||||
if err != nil {
|
||||
exception.New("解析默认应用失败 %s", 500, err).Throw()
|
||||
}
|
||||
|
||||
info.Icons.Set("icns", xfs.Encode(data.MustAsset("yao/data/icons/icon.icns")))
|
||||
info.Icons.Set("ico", xfs.Encode(data.MustAsset("yao/data/icons/icon.ico")))
|
||||
info.Icons.Set("png", xfs.Encode(data.MustAsset("yao/data/icons/icon.png")))
|
||||
|
||||
return info
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
os.Setenv("YAO_LANG", "zh-cn")
|
||||
Load(config.Conf)
|
||||
// assert.Equal(t, "YAO", share.App.L["Yao"])
|
||||
// assert.Equal(t, "象传", share.App.L["Xiang"])
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# Brain
|
||||
|
||||
the robot who helps you build various types of applications
|
||||
|
||||
the robot has two modes :
|
||||
|
||||
1. Generate an App DSL based on the rules
|
||||
2. Connect AI cloud to generate app DSL based on input ( Not Supported Yet )
|
||||
|
|
@ -1 +0,0 @@
|
|||
package listen
|
||||
|
|
@ -1 +0,0 @@
|
|||
package send
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# Zouyu
|
||||
|
||||
Zouyu is a benevolent beast in ancient Chinese myths and legends. It is a very precious mythical beast in Lin's country. It is like a tiger, with colorful patterns on its body, and its tail is longer than its body. It looks like a tiger with white hair and black stripes, but it does not eat live animals. Travel thousands of miles a day.
|
||||
|
||||
## Functions
|
||||
|
||||
Connect a Database, generates a dashboard applications
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
package zouyu
|
||||
|
||||
type conn struct{}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package zouyu
|
||||
|
||||
// Run the data
|
||||
func Run(dsn string) {}
|
||||
|
||||
func (conn *conn) models() {}
|
||||
|
||||
func (conn *conn) apis() {}
|
||||
|
||||
func (conn *conn) flows() {}
|
||||
|
||||
func (conn *conn) tables() {}
|
||||
|
||||
func (conn *conn) env() {}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package brain
|
||||
|
||||
// NewBehaviors Returns the behaviors based on input words
|
||||
func NewBehaviors(words string) (*Behaviors, error) {
|
||||
resp, err := NPL(words)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Behaviors, nil
|
||||
}
|
||||
|
||||
// Run the behaviors
|
||||
func (behaviors *Behaviors) Run() {}
|
||||
|
||||
// NPL the Natural language processing
|
||||
func NPL(words string) (*Response, error) {
|
||||
return &Response{Behaviors: &Behaviors{}}, nil
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package brain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewBehaviors(t *testing.T) {
|
||||
behaviors, err := NewBehaviors("hello")
|
||||
fmt.Println(behaviors, err)
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
# Command Line Interface
|
||||
|
|
@ -1 +0,0 @@
|
|||
package cli
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Cloud
|
||||
|
||||
Connecting AI cloud to analyze behaviors
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package brain
|
||||
|
||||
// Behaviors the Behaviors struct
|
||||
type Behaviors struct{}
|
||||
|
||||
// Response NPL Response
|
||||
type Response struct {
|
||||
Behaviors *Behaviors
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
# WEB Interface
|
||||
30
cert/cert.go
30
cert/cert.go
|
|
@ -1,35 +1,17 @@
|
|||
package cert
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/ssl"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load 加载API
|
||||
func Load(cfg config.Config) error {
|
||||
var root = filepath.Join(cfg.Root, "certs")
|
||||
return LoadFrom(root, "")
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".pem", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
_, err := ssl.LoadCertificateFrom(filename, name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
exts := []string{"*.pem", "*.key", "*.pub"}
|
||||
return application.App.Walk("certs", func(root, file string, isdir bool) error {
|
||||
_, err := ssl.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,20 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/gou/ssl"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func TestProcessSign(t *testing.T) {
|
||||
Load(config.Conf)
|
||||
args := []interface{}{"hello world", "private", "SHA256"}
|
||||
signature, err := gou.NewProcess("ssl.Sign", args...).Exec()
|
||||
signature, err := process.New("ssl.Sign", args...).Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -29,7 +28,7 @@ func TestProcessVerify(t *testing.T) {
|
|||
Load(config.Conf)
|
||||
signature := "EDHf3C9TXEk7y8LzIk5czLefXZyGxcMDVMcbNuBBegDkTqnPsRQnhFtNOgCdox8lI3MzLatwjoljoMY4Qk+sHGd5mAHMpiREa1gRFSVYpA2xvXZ3+KsfOHAdICQrfUdy59QaJGo6iGPNGG8PQOXHPTVNn6LMfryat9+f4l21DPAZiT0RyCUgFZE3/Qv8Z/6J4AsIXMSKZD6BGPPHUxGe7UBrXZvcR5dX25EiNjuH2OO38YJnDiTRVw14UI5fk/mQrwRdezj5tSKFCyHt912BZExXtkHISiYFNTZ/2RhOup5Xx6o3GvrEOdshrnN80Lwu1Aaju+lnZp13hDz4P6hU7w=="
|
||||
args := []interface{}{"hello world", signature, "cert", "SHA256"}
|
||||
res, err := gou.NewProcess("ssl.Verify", args...).Exec()
|
||||
res, err := process.New("ssl.Verify", args...).Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
# 数据图表
|
||||
60
chart/api.go
60
chart/api.go
|
|
@ -1,60 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// SetupAPIs 设定API数据
|
||||
func (chart *Chart) SetupAPIs() {
|
||||
|
||||
defaults := map[string]share.API{
|
||||
"data": apiDataDefault(),
|
||||
"setting": apiSettingDefault(),
|
||||
}
|
||||
|
||||
// 开发者填写的规则
|
||||
for name := range chart.APIs {
|
||||
if _, has := defaults[name]; !has {
|
||||
delete(chart.APIs, name)
|
||||
continue
|
||||
}
|
||||
|
||||
api := defaults[name]
|
||||
api.Name = name
|
||||
if chart.APIs[name].Process != "" {
|
||||
api.Process = chart.APIs[name].Process
|
||||
}
|
||||
|
||||
if chart.APIs[name].Guard != "" {
|
||||
api.Guard = chart.APIs[name].Guard
|
||||
}
|
||||
|
||||
if chart.APIs[name].Default != nil {
|
||||
api.Default = chart.APIs[name].Default
|
||||
}
|
||||
|
||||
defaults[name] = api
|
||||
}
|
||||
|
||||
chart.APIs = defaults
|
||||
}
|
||||
|
||||
// apiSearchDefault data 接口默认值
|
||||
func apiDataDefault() share.API {
|
||||
param := map[string]interface{}{}
|
||||
return share.API{
|
||||
Name: "data",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "xiang.chart.data",
|
||||
Default: []interface{}{param},
|
||||
}
|
||||
}
|
||||
|
||||
// apiSettingDefault setting 接口默认值
|
||||
func apiSettingDefault() share.API {
|
||||
return share.API{
|
||||
Name: "setting",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "xiang.chart.setting",
|
||||
}
|
||||
}
|
||||
103
chart/chart.go
103
chart/chart.go
|
|
@ -1,103 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/lang"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Charts 已载入图表
|
||||
var Charts = map[string]*Chart{}
|
||||
|
||||
// Load 加载数据表格
|
||||
func Load(cfg config.Config) error {
|
||||
if share.BUILDIN {
|
||||
return LoadBuildIn("charts", "")
|
||||
}
|
||||
return LoadFrom(filepath.Join(cfg.Root, "charts"), "")
|
||||
}
|
||||
|
||||
// LoadBuildIn 从制品中读取
|
||||
func LoadBuildIn(dir string, prefix string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := LoadChart(content, name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Load Script
|
||||
err = share.Walk(dir, ".js", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
chart := Select(name)
|
||||
if chart != nil {
|
||||
script := share.ScriptName(filename)
|
||||
content := share.ReadFile(filename)
|
||||
chart.LoadScript(string(content), script)
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// LoadChart 载入数据表格
|
||||
func LoadChart(source []byte, name string) (*Chart, error) {
|
||||
chart := &Chart{
|
||||
Flow: &gou.Flow{Name: name},
|
||||
}
|
||||
err := jsoniter.Unmarshal(source, chart)
|
||||
if err != nil {
|
||||
log.With(log.F{"name": name, "source": source}).Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
chart.Prepare()
|
||||
chart.SetupAPIs()
|
||||
Charts[name] = chart
|
||||
|
||||
// Apply a language pack
|
||||
if lang.Default != nil {
|
||||
lang.Default.Apply(Charts[name])
|
||||
}
|
||||
|
||||
return chart, nil
|
||||
}
|
||||
|
||||
// Select 读取已加载图表
|
||||
func Select(name string) *Chart {
|
||||
chart, has := Charts[name]
|
||||
if !has {
|
||||
exception.New(
|
||||
fmt.Sprintf("Chart:%s; 尚未加载", name),
|
||||
400,
|
||||
).Throw()
|
||||
}
|
||||
return chart
|
||||
}
|
||||
|
||||
// GetData 运行 flow 返回数值
|
||||
func (chart Chart) GetData(params map[string]interface{}) interface{} {
|
||||
return chart.Flow.Exec(params)
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
|
||||
share.DBConnect(config.Conf.DB)
|
||||
model.Load(config.Conf)
|
||||
query.Load(config.Conf)
|
||||
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range Charts {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 3, len(keys))
|
||||
_, err := i18n.Trans("zh-hk", []string{"chart.lang"}, Charts["lang"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// lang := new.(*Chart)
|
||||
// utils.Dump(lang.Output)
|
||||
|
||||
// output := lang.Output.(map[string]interface{})
|
||||
// assert.Equal(t, "{{$in}}", output["參數"])
|
||||
|
||||
// filters := lang.Page.Layout["filters"].([]interface{})
|
||||
// begin := filters[0].(map[string]interface{})
|
||||
// assert.Equal(t, "開始時間", begin["name"])
|
||||
|
||||
// assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
||||
}
|
||||
125
chart/lang.go
125
chart/lang.go
|
|
@ -1,125 +0,0 @@
|
|||
package chart
|
||||
|
||||
// Lang for applying a language pack
|
||||
func (chart *Chart) Lang(trans func(widget string, inst string, value *string) bool) {
|
||||
inst := chart.Flow.Name
|
||||
widget := "chart"
|
||||
|
||||
trans(widget, inst, &chart.Name)
|
||||
trans(widget, inst, &chart.Label)
|
||||
trans(widget, inst, &chart.Description)
|
||||
trans(widget, inst, &chart.Page.Primary)
|
||||
transMap(widget, inst, chart.Page.Layout, trans)
|
||||
chart.Output = transAny(widget, inst, chart.Output, trans)
|
||||
|
||||
// Filters
|
||||
for name, filter := range chart.Filters {
|
||||
new := name
|
||||
trans(widget, inst, &new)
|
||||
trans(widget, inst, &filter.Label)
|
||||
delete(chart.Filters, name)
|
||||
|
||||
// Props
|
||||
transMap(widget, inst, filter.Input.Props, trans)
|
||||
chart.Filters[new] = filter
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func transAny(widget string, inst string, input interface{}, trans func(widget string, inst string, value *string) bool) interface{} {
|
||||
switch input.(type) {
|
||||
case []interface{}:
|
||||
values := input.([]interface{})
|
||||
transArr(widget, inst, values, trans)
|
||||
input = values
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
values := input.(map[string]interface{})
|
||||
for name, value := range values {
|
||||
new := name
|
||||
newValue := value
|
||||
|
||||
switch value.(type) {
|
||||
case string:
|
||||
val := value.(string)
|
||||
trans(widget, inst, &val)
|
||||
newValue = val
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
vals := value.([]interface{})
|
||||
transArr(widget, inst, vals, trans)
|
||||
newValue = vals
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
vals := value.(map[string]interface{})
|
||||
transMap(widget, inst, vals, trans)
|
||||
newValue = vals
|
||||
break
|
||||
}
|
||||
|
||||
trans(widget, inst, &new)
|
||||
delete(values, name)
|
||||
values[new] = newValue
|
||||
}
|
||||
input = values
|
||||
break
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
func transMap(widget string, inst string, values map[string]interface{}, trans func(widget string, inst string, value *string) bool) {
|
||||
for key, value := range values {
|
||||
|
||||
switch value.(type) {
|
||||
|
||||
case string:
|
||||
v := value.(string)
|
||||
trans(widget, inst, &v)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
v := value.([]interface{})
|
||||
transArr(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
v := value.(map[string]interface{})
|
||||
transMap(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func transArr(widget string, inst string, values []interface{}, trans func(widget string, inst string, value *string) bool) {
|
||||
for key, value := range values {
|
||||
switch value.(type) {
|
||||
|
||||
case string:
|
||||
v := value.(string)
|
||||
trans(widget, inst, &v)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
v := value.([]interface{})
|
||||
transArr(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
v := value.(map[string]interface{})
|
||||
transMap(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
// 注册处理器
|
||||
func init() {
|
||||
gou.RegisterProcessHandler("xiang.chart.data", ProcessData)
|
||||
gou.RegisterProcessHandler("xiang.chart.setting", ProcessSetting)
|
||||
}
|
||||
|
||||
// ProcessData xiang.chart.data
|
||||
// 查询数据分析图表中定义的数据
|
||||
func ProcessData(process *gou.Process) interface{} {
|
||||
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
params := process.ArgsMap(1)
|
||||
chart := Select(name)
|
||||
api := chart.APIs["data"]
|
||||
|
||||
if len(api.Default) > 0 {
|
||||
if defaults, ok := api.Default[0].(map[string]interface{}); ok {
|
||||
for key, value := range defaults {
|
||||
if !params.Has(key) {
|
||||
params.Set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// with Session
|
||||
chart.Flow.WithGlobal(process.Global)
|
||||
chart.Flow.WithSID(process.Sid)
|
||||
|
||||
return chart.GetData(params)
|
||||
}
|
||||
|
||||
// ProcessSetting xiang.chart.setting
|
||||
// 查询数据分析图表中定义的数据
|
||||
func ProcessSetting(process *gou.Process) interface{} {
|
||||
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
field := process.ArgsString(1)
|
||||
chart := Select(name)
|
||||
|
||||
fields := strings.Split(field, ",")
|
||||
setting := maps.Map{
|
||||
"name": chart.Name,
|
||||
"label": chart.Label,
|
||||
"version": chart.Version,
|
||||
"description": chart.Description,
|
||||
"filters": chart.Filters,
|
||||
"page": chart.Page,
|
||||
}
|
||||
|
||||
if len(fields) == 1 && setting.Has(fields[0]) {
|
||||
field := strings.TrimSpace(fields[0])
|
||||
return setting.Get(field)
|
||||
}
|
||||
|
||||
if len(fields) > 1 {
|
||||
res := maps.Map{}
|
||||
for _, field := range fields {
|
||||
field = strings.TrimSpace(field)
|
||||
if setting.Has(field) {
|
||||
res.Set(field, setting.Get(field))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
return setting
|
||||
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/session"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/yao/config"
|
||||
_ "github.com/yaoapp/yao/helper"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func init() {
|
||||
runtime.Load(config.Conf)
|
||||
share.DBConnect(config.Conf.DB)
|
||||
model.Load(config.Conf)
|
||||
query.Load(config.Conf)
|
||||
Load(config.Conf)
|
||||
}
|
||||
func TestProcessSetting(t *testing.T) {
|
||||
|
||||
args := []interface{}{
|
||||
"service.compare",
|
||||
nil,
|
||||
&gin.Context{},
|
||||
}
|
||||
process := gou.NewProcess("xiang.chart.Setting", args...)
|
||||
response := ProcessSetting(process)
|
||||
assert.NotNil(t, response)
|
||||
res := any.Of(response).Map()
|
||||
assert.True(t, res.Has("name"))
|
||||
assert.True(t, res.Has("label"))
|
||||
assert.True(t, res.Has("description"))
|
||||
assert.True(t, res.Has("page"))
|
||||
assert.True(t, res.Has("version"))
|
||||
|
||||
args = []interface{}{
|
||||
"service.compare",
|
||||
"page,name",
|
||||
&gin.Context{},
|
||||
}
|
||||
process = gou.NewProcess("xiang.chart.Setting", args...)
|
||||
response = ProcessSetting(process)
|
||||
assert.NotNil(t, response)
|
||||
|
||||
res = any.Of(response).Map()
|
||||
assert.True(t, res.Has("name"))
|
||||
assert.True(t, res.Has("page"))
|
||||
assert.False(t, res.Has("label"))
|
||||
}
|
||||
|
||||
func TestProcessData(t *testing.T) {
|
||||
|
||||
params := url.Values{
|
||||
"from": []string{"1981-01-01", "1990-01-01"},
|
||||
}
|
||||
params.Set("to", "2049-12-31")
|
||||
|
||||
args := []interface{}{
|
||||
"service.compare",
|
||||
params,
|
||||
&gin.Context{},
|
||||
}
|
||||
process := gou.NewProcess("xiang.chart.Data", args...)
|
||||
response := ProcessData(process)
|
||||
// utils.Dump(response)
|
||||
|
||||
assert.NotNil(t, response)
|
||||
|
||||
res := any.Of(response).Map().Dot()
|
||||
assert.Equal(t, "北京", res.Get("合并.0.城市"))
|
||||
}
|
||||
|
||||
func TestProcessDataGlobalSession(t *testing.T) {
|
||||
|
||||
params := url.Values{
|
||||
"from": []string{"1981-01-01", "1990-01-01"},
|
||||
}
|
||||
params.Set("to", "2049-12-31")
|
||||
|
||||
args := []interface{}{
|
||||
"session",
|
||||
params,
|
||||
&gin.Context{},
|
||||
}
|
||||
|
||||
sid := session.ID()
|
||||
data := time.Now().String()
|
||||
session.Global().ID(sid).Set("id", data)
|
||||
process := gou.
|
||||
NewProcess("xiang.chart.Data", args...).
|
||||
WithSID(sid).
|
||||
WithGlobal(map[string]interface{}{"foo": "bar"})
|
||||
|
||||
response := ProcessData(process)
|
||||
res := any.Of(response).Map().Dot()
|
||||
assert.Equal(t, data, res.Get("ID"))
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Chart 图表格式
|
||||
type Chart struct {
|
||||
*gou.Flow
|
||||
APIs map[string]share.API `json:"apis,omitempty"`
|
||||
Filters map[string]share.Filter `json:"filters,omitempty"`
|
||||
Page share.Page `json:"page,omitempty"`
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/engine"
|
||||
|
|
@ -71,7 +71,7 @@ var dumpCmd = &cobra.Command{
|
|||
|
||||
// Export models
|
||||
files := []string{}
|
||||
for _, mod := range gou.Models {
|
||||
for _, mod := range model.Models {
|
||||
|
||||
fmt.Printf("\r%s", color.GreenString(L("Export the models: %s (%s)"), mod.Name, mod.MetaData.Table.Name))
|
||||
jsonfiles, err := mod.Export(5000, func(curr, total int) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/engine"
|
||||
|
|
@ -43,7 +43,7 @@ var migrateCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
if name != "" {
|
||||
mod, has := gou.Models[name]
|
||||
mod, has := model.Models[name]
|
||||
fmt.Printf(color.WhiteString(L("Update schema model: %s (%s) "), mod.Name, mod.MetaData.Table.Name) + "\t")
|
||||
|
||||
if !has {
|
||||
|
|
@ -70,7 +70,7 @@ var migrateCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
// Do Stuff Here
|
||||
for _, mod := range gou.Models {
|
||||
for _, mod := range model.Models {
|
||||
fmt.Printf(color.WhiteString(L("Update schema model: %s (%s) "), mod.Name, mod.MetaData.Table.Name) + "\t")
|
||||
|
||||
if resetModel {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/engine"
|
||||
|
|
@ -113,7 +113,7 @@ func restoreModels(basePath string) {
|
|||
}
|
||||
|
||||
// Migrate models
|
||||
for _, mod := range gou.Models {
|
||||
for _, mod := range model.Models {
|
||||
fmt.Printf("\r%s", strings.Repeat(" ", 80))
|
||||
fmt.Printf(color.GreenString(L("\rUpdate schema model: %s (%s) "), mod.Name, mod.MetaData.Table.Name))
|
||||
err := mod.Migrate(true)
|
||||
|
|
@ -128,7 +128,7 @@ func restoreModels(basePath string) {
|
|||
for _, file := range files {
|
||||
namer := strings.Split(file.Name(), ".")
|
||||
name := strings.Join(namer[:len(namer)-2], ".")
|
||||
if mod, has := gou.Models[name]; has {
|
||||
if mod, has := model.Models[name]; has {
|
||||
fmt.Printf("\r%s", strings.Repeat(" ", 80))
|
||||
fmt.Printf(color.GreenString(L("\rRestore model: %s (%s) "), mod.Name, mod.MetaData.Table.Name))
|
||||
err := mod.Import(filepath.Join(basePath, file.Name()))
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ func init() {
|
|||
getCmd,
|
||||
dumpCmd,
|
||||
restoreCmd,
|
||||
socketCmd,
|
||||
websocketCmd,
|
||||
// socketCmd,
|
||||
// websocketCmd,
|
||||
studioCmd,
|
||||
upgradeCmd,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import (
|
|||
"github.com/fatih/color"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/utils"
|
||||
"github.com/yaoapp/yao/config"
|
||||
|
|
@ -21,7 +22,7 @@ var runCmd = &cobra.Command{
|
|||
Long: L("Execute process"),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
defer share.SessionStop()
|
||||
defer gou.KillPlugins()
|
||||
defer plugin.KillAll()
|
||||
defer func() {
|
||||
err := exception.Catch(recover())
|
||||
if err != nil {
|
||||
|
|
@ -69,7 +70,7 @@ var runCmd = &cobra.Command{
|
|||
|
||||
}
|
||||
|
||||
process := gou.NewProcess(name, pargs...)
|
||||
process := process.New(name, pargs...)
|
||||
res := process.Run()
|
||||
fmt.Println(color.WhiteString("--------------------------------------"))
|
||||
fmt.Println(color.WhiteString(L("%s Response"), name))
|
||||
|
|
|
|||
174
cmd/service.go
174
cmd/service.go
|
|
@ -1,174 +0,0 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// **** DEPRECATED ****
|
||||
var serviceCmd = &cobra.Command{
|
||||
Use: "service",
|
||||
Short: L("Service manager"),
|
||||
Long: L("Service manager"),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
loadService(config.Conf)
|
||||
command := "ps"
|
||||
if len(args) > 0 {
|
||||
command = args[0]
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
args = args[1:]
|
||||
} else {
|
||||
args = []string{}
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "ps":
|
||||
services()
|
||||
break
|
||||
case "install", "start", "stop", "remove", "status":
|
||||
serviceManage(command, args)
|
||||
break
|
||||
default:
|
||||
serviceHelp()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func serviceHelp() {
|
||||
fmt.Println("Usage:")
|
||||
fmt.Println(" ", color.GreenString(L("%s service [ps|start|stop|install|status] [all|name]"), share.BUILDNAME))
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func serviceManageAll(command string) {
|
||||
for name := range gou.Services {
|
||||
if name == "all" {
|
||||
continue
|
||||
}
|
||||
serviceManage(command, []string{name})
|
||||
}
|
||||
}
|
||||
|
||||
func serviceManage(command string, args []string) {
|
||||
if len(args) == 0 {
|
||||
serviceHelp()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := exception.Catch(recover())
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
name := args[0]
|
||||
if name == "all" {
|
||||
serviceManageAll(command)
|
||||
return
|
||||
}
|
||||
|
||||
srv := gou.SelectService(name)
|
||||
var status = ""
|
||||
var err error
|
||||
switch command {
|
||||
case "install":
|
||||
status, err = srv.Install()
|
||||
break
|
||||
case "start":
|
||||
status, err = srv.Start()
|
||||
break
|
||||
case "stop":
|
||||
status, err = srv.Stop()
|
||||
break
|
||||
case "remove":
|
||||
status, err = srv.Remove()
|
||||
break
|
||||
case "status":
|
||||
status, err = srv.Status()
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
}
|
||||
|
||||
fmt.Println(status)
|
||||
}
|
||||
|
||||
func services() {
|
||||
for name, srv := range gou.Services {
|
||||
status, err := srv.Status()
|
||||
if err != nil {
|
||||
status = err.Error()
|
||||
}
|
||||
fmt.Println(
|
||||
color.GreenString("%s", name),
|
||||
srv.Name, "....",
|
||||
statusInfo(status),
|
||||
)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func statusInfo(message string) string {
|
||||
if strings.Contains(message, "stopped") {
|
||||
return statusStop()
|
||||
} else if strings.Contains(message, "not installed") {
|
||||
return statusNotInstalled()
|
||||
} else if strings.Contains(message, "running") {
|
||||
return statusRunning()
|
||||
}
|
||||
return statusUnknown()
|
||||
}
|
||||
|
||||
func statusUnknown() string {
|
||||
return fmt.Sprintf("[ %s ]", color.WhiteString("UNKNOWN"))
|
||||
}
|
||||
|
||||
func statusRunning() string {
|
||||
return fmt.Sprintf("[ %s ]", color.GreenString("RUNNING"))
|
||||
}
|
||||
|
||||
func statusNotInstalled() string {
|
||||
return fmt.Sprintf("[ %s ]", color.YellowString("NOT INSTALLED"))
|
||||
}
|
||||
|
||||
func statusStop() string {
|
||||
return fmt.Sprintf("[ %s ]", color.RedString("STOPED"))
|
||||
}
|
||||
|
||||
// Load 加载API
|
||||
func loadService(cfg config.Config) {
|
||||
var root = filepath.Join(cfg.Root, "services")
|
||||
loadServiceFrom(root, "")
|
||||
}
|
||||
|
||||
func loadServiceFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".srv.json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadService(string(content), name)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
os.Exit(1)
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
@ -7,7 +7,8 @@ import (
|
|||
"github.com/fatih/color"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/gou/socket"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/engine"
|
||||
|
|
@ -20,7 +21,7 @@ var socketCmd = &cobra.Command{
|
|||
Long: L("Open a socket connection"),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
defer share.SessionStop()
|
||||
defer gou.KillPlugins()
|
||||
defer plugin.KillAll()
|
||||
defer func() {
|
||||
err := exception.Catch(recover())
|
||||
if err != nil {
|
||||
|
|
@ -67,7 +68,7 @@ var socketCmd = &cobra.Command{
|
|||
|
||||
}
|
||||
|
||||
socket, has := gou.Sockets[name]
|
||||
socket, has := socket.Sockets[name]
|
||||
if !has {
|
||||
fmt.Println(color.RedString(L("%s not exists!"), name))
|
||||
return
|
||||
|
|
|
|||
20
cmd/start.go
20
cmd/start.go
|
|
@ -12,8 +12,9 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/api"
|
||||
"github.com/yaoapp/gou/connector"
|
||||
"github.com/yaoapp/gou/schedule"
|
||||
"github.com/yaoapp/gou/store"
|
||||
"github.com/yaoapp/gou/task"
|
||||
"github.com/yaoapp/gou/websocket"
|
||||
|
|
@ -152,14 +153,17 @@ var startCmd = &cobra.Command{
|
|||
printStores(true)
|
||||
}
|
||||
|
||||
srv, err := service.Start()
|
||||
|
||||
// Start server
|
||||
go func() {
|
||||
err := service.Start()
|
||||
srv.Start()
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
os.Exit(3)
|
||||
}
|
||||
}()
|
||||
defer srv.Stop()
|
||||
|
||||
fmt.Println(color.GreenString(L("✨LISTENING✨")))
|
||||
|
||||
|
|
@ -256,12 +260,12 @@ func printStudio(silent bool, host string) {
|
|||
|
||||
func printSchedules(silent bool) {
|
||||
|
||||
if len(gou.Schedules) == 0 {
|
||||
if len(schedule.Schedules) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if silent {
|
||||
for name, sch := range gou.Schedules {
|
||||
for name, sch := range schedule.Schedules {
|
||||
process := fmt.Sprintf("Process: %s", sch.Process)
|
||||
if sch.TaskName != "" {
|
||||
process = fmt.Sprintf("Task: %s", sch.TaskName)
|
||||
|
|
@ -272,9 +276,9 @@ func printSchedules(silent bool) {
|
|||
}
|
||||
|
||||
fmt.Println(color.WhiteString("\n---------------------------------"))
|
||||
fmt.Println(color.WhiteString(L("Schedules List (%d)"), len(gou.Schedules)))
|
||||
fmt.Println(color.WhiteString(L("Schedules List (%d)"), len(schedule.Schedules)))
|
||||
fmt.Println(color.WhiteString("---------------------------------"))
|
||||
for name, sch := range gou.Schedules {
|
||||
for name, sch := range schedule.Schedules {
|
||||
process := fmt.Sprintf("Process: %s", sch.Process)
|
||||
if sch.TaskName != "" {
|
||||
process = fmt.Sprintf("Task: %s", sch.TaskName)
|
||||
|
|
@ -309,7 +313,7 @@ func printTasks(silent bool) {
|
|||
func printApis(silent bool) {
|
||||
|
||||
if silent {
|
||||
for _, api := range gou.APIs {
|
||||
for _, api := range api.APIs {
|
||||
if len(api.HTTP.Paths) <= 0 {
|
||||
continue
|
||||
}
|
||||
|
|
@ -328,7 +332,7 @@ func printApis(silent bool) {
|
|||
fmt.Println(color.WhiteString(L("API List")))
|
||||
fmt.Println(color.WhiteString("---------------------------------"))
|
||||
|
||||
for _, api := range gou.APIs { // API信息
|
||||
for _, api := range api.APIs { // API信息
|
||||
if len(api.HTTP.Paths) <= 0 {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import (
|
|||
"github.com/fatih/color"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/utils"
|
||||
"github.com/yaoapp/yao/config"
|
||||
|
|
@ -22,7 +23,7 @@ var RunCmd = &cobra.Command{
|
|||
Long: L("Execute Yao Studio Script"),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
defer share.SessionStop()
|
||||
defer gou.KillPlugins()
|
||||
defer plugin.KillAll()
|
||||
defer func() {
|
||||
err := exception.Catch(recover())
|
||||
if err != nil {
|
||||
|
|
@ -71,8 +72,18 @@ var RunCmd = &cobra.Command{
|
|||
}
|
||||
}
|
||||
|
||||
req := gou.Yao.New(service, method)
|
||||
res, err := req.RootCall(pargs...)
|
||||
script, err := v8.SelectRoot(service)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
}
|
||||
|
||||
ctx, err := script.NewContext("", nil)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
}
|
||||
defer ctx.Close()
|
||||
|
||||
res, err := ctx.Call(method, pargs...)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString("--------------------------------------"))
|
||||
fmt.Println(color.RedString(L("%s Error"), args[0]))
|
||||
|
|
|
|||
115
cmd/websocket.go
115
cmd/websocket.go
|
|
@ -1,71 +1,58 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
// var websocketCmd = &cobra.Command{
|
||||
// Use: "websocket",
|
||||
// Short: L("Open a websocket connection"),
|
||||
// Long: L("Open a websocket connection"),
|
||||
// Run: func(cmd *cobra.Command, args []string) {
|
||||
// defer share.SessionStop()
|
||||
// defer plugin.KillAll()
|
||||
// defer func() {
|
||||
// err := exception.Catch(recover())
|
||||
// if err != nil {
|
||||
// fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
// }
|
||||
// }()
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/engine"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
// Boot()
|
||||
// cfg := config.Conf
|
||||
// cfg.Session.IsCLI = true
|
||||
// engine.Load(cfg)
|
||||
// if len(args) < 1 {
|
||||
// fmt.Println(color.RedString(L("Not enough arguments")))
|
||||
// fmt.Println(color.WhiteString(share.BUILDNAME + " help"))
|
||||
// return
|
||||
// }
|
||||
|
||||
var websocketCmd = &cobra.Command{
|
||||
Use: "websocket",
|
||||
Short: L("Open a websocket connection"),
|
||||
Long: L("Open a websocket connection"),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
defer share.SessionStop()
|
||||
defer gou.KillPlugins()
|
||||
defer func() {
|
||||
err := exception.Catch(recover())
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
}
|
||||
}()
|
||||
// name := args[0]
|
||||
// websocket, has := websocket.WebSockets[name]
|
||||
// if !has {
|
||||
// fmt.Println(color.RedString(L("%s not exists!"), name))
|
||||
// return
|
||||
// }
|
||||
|
||||
Boot()
|
||||
cfg := config.Conf
|
||||
cfg.Session.IsCLI = true
|
||||
engine.Load(cfg)
|
||||
if len(args) < 1 {
|
||||
fmt.Println(color.RedString(L("Not enough arguments")))
|
||||
fmt.Println(color.WhiteString(share.BUILDNAME + " help"))
|
||||
return
|
||||
}
|
||||
// url := websocket.URL
|
||||
// protocols := websocket.Protocols
|
||||
// argsLen := len(args)
|
||||
// if argsLen > 1 {
|
||||
// url = args[1]
|
||||
// }
|
||||
|
||||
name := args[0]
|
||||
websocket, has := gou.WebSockets[name]
|
||||
if !has {
|
||||
fmt.Println(color.RedString(L("%s not exists!"), name))
|
||||
return
|
||||
}
|
||||
// if argsLen > 2 {
|
||||
// protocols = args[2:]
|
||||
// }
|
||||
|
||||
url := websocket.URL
|
||||
protocols := websocket.Protocols
|
||||
argsLen := len(args)
|
||||
if argsLen > 1 {
|
||||
url = args[1]
|
||||
}
|
||||
|
||||
if argsLen > 2 {
|
||||
protocols = args[2:]
|
||||
}
|
||||
|
||||
fmt.Println(color.WhiteString("\n---------------------------------"))
|
||||
fmt.Println(color.WhiteString(websocket.Name))
|
||||
fmt.Println(color.WhiteString("---------------------------------"))
|
||||
fmt.Println(color.GreenString(" URL: %s", url))
|
||||
fmt.Println(color.GreenString("Protocols: %s", strings.Join(protocols, ",")))
|
||||
fmt.Println(color.WhiteString("--------------------------------------"))
|
||||
pargs := append([]string{url}, protocols...)
|
||||
err := websocket.Open(pargs...)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("%s"), err.Error()))
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
// fmt.Println(color.WhiteString("\n---------------------------------"))
|
||||
// fmt.Println(color.WhiteString(websocket.Name))
|
||||
// fmt.Println(color.WhiteString("---------------------------------"))
|
||||
// fmt.Println(color.GreenString(" URL: %s", url))
|
||||
// fmt.Println(color.GreenString("Protocols: %s", strings.Join(protocols, ",")))
|
||||
// fmt.Println(color.WhiteString("--------------------------------------"))
|
||||
// pargs := append([]string{url}, protocols...)
|
||||
// err := websocket.Open(pargs...)
|
||||
// if err != nil {
|
||||
// fmt.Println(color.RedString(L("%s"), err.Error()))
|
||||
// return
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ var Conf Config
|
|||
// LogOutput 日志输出
|
||||
var LogOutput *os.File // 日志文件
|
||||
|
||||
// DSLExtensions the dsl file Extensions
|
||||
var DSLExtensions = []string{".yao", ".json", ".jsonc"}
|
||||
|
||||
func init() {
|
||||
filename, _ := filepath.Abs(filepath.Join(".", ".env"))
|
||||
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
|
||||
|
|
|
|||
|
|
@ -4,65 +4,65 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestMD4(t *testing.T) {
|
||||
// Hash
|
||||
args := []interface{}{"MD4", "123456"}
|
||||
res := gou.NewProcess("yao.crypto.hash", args...).Run()
|
||||
res := process.New("yao.crypto.hash", args...).Run()
|
||||
assert.Equal(t, "585028aa0f794af812ee3be8804eb14a", res)
|
||||
|
||||
// HMac
|
||||
args = append(args, "123456")
|
||||
res = gou.NewProcess("yao.crypto.hmac", args...).Run()
|
||||
res = process.New("yao.crypto.hmac", args...).Run()
|
||||
assert.Equal(t, "356f45727db95d65843b2794474d741c", res)
|
||||
}
|
||||
|
||||
func TestMD5(t *testing.T) {
|
||||
// Hash
|
||||
args := []interface{}{"MD5", "123456"}
|
||||
res := gou.NewProcess("yao.crypto.hash", args...).Run()
|
||||
res := process.New("yao.crypto.hash", args...).Run()
|
||||
assert.Equal(t, "e10adc3949ba59abbe56e057f20f883e", res)
|
||||
|
||||
// HMac
|
||||
args = append(args, "123456")
|
||||
res = gou.NewProcess("yao.crypto.hmac", args...).Run()
|
||||
res = process.New("yao.crypto.hmac", args...).Run()
|
||||
assert.Equal(t, "30ce71a73bdd908c3955a90e8f7429ef", res)
|
||||
}
|
||||
|
||||
func TestSHA1(t *testing.T) {
|
||||
// Hash
|
||||
args := []interface{}{"SHA1", "123456"}
|
||||
res := gou.NewProcess("yao.crypto.hash", args...).Run()
|
||||
res := process.New("yao.crypto.hash", args...).Run()
|
||||
assert.Equal(t, "7c4a8d09ca3762af61e59520943dc26494f8941b", res)
|
||||
|
||||
// HMac
|
||||
args = append(args, "123456")
|
||||
res = gou.NewProcess("yao.crypto.hmac", args...).Run()
|
||||
res = process.New("yao.crypto.hmac", args...).Run()
|
||||
assert.Equal(t, "74b55b6ab2b8e438ac810435e369e3047b3951d0", res)
|
||||
}
|
||||
|
||||
func TestSHA256(t *testing.T) {
|
||||
// Hash
|
||||
args := []interface{}{"SHA256", "123456"}
|
||||
res := gou.NewProcess("yao.crypto.hash", args...).Run()
|
||||
res := process.New("yao.crypto.hash", args...).Run()
|
||||
assert.Equal(t, "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", res)
|
||||
|
||||
// HMac
|
||||
args = append(args, "123456")
|
||||
res = gou.NewProcess("yao.crypto.hmac", args...).Run()
|
||||
res = process.New("yao.crypto.hmac", args...).Run()
|
||||
assert.Equal(t, "b8ad08a3a547e35829b821b75370301dd8c4b06bdd7771f9b541a75914068718", res)
|
||||
}
|
||||
|
||||
func TestSHA1Base64(t *testing.T) {
|
||||
// Hash
|
||||
args := []interface{}{"SHA1", "123456"}
|
||||
res := gou.NewProcess("yao.crypto.hash", args...).Run()
|
||||
res := process.New("yao.crypto.hash", args...).Run()
|
||||
assert.Equal(t, "7c4a8d09ca3762af61e59520943dc26494f8941b", res)
|
||||
|
||||
// HMac
|
||||
args = append(args, "123456", "base64")
|
||||
res = gou.NewProcess("yao.crypto.hmac", args...).Run()
|
||||
res = process.New("yao.crypto.hmac", args...).Run()
|
||||
assert.Equal(t, "dLVbarK45DisgQQ142njBHs5UdA=", res)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gou.RegisterProcessHandler("yao.crypto.hash", ProcessHash) // deprecated → crypto.Hash
|
||||
gou.RegisterProcessHandler("yao.crypto.hmac", ProcessHmac) // deprecated → crypto.Hash
|
||||
process.Register("yao.crypto.hash", ProcessHash) // deprecated → crypto.Hash
|
||||
process.Register("yao.crypto.hmac", ProcessHmac) // deprecated → crypto.Hash
|
||||
|
||||
gou.AliasProcess("yao.crypto.hash", "crypto.Hash")
|
||||
gou.AliasProcess("yao.crypto.hmac", "crypto.Hmac")
|
||||
process.Alias("yao.crypto.hash", "crypto.Hash")
|
||||
process.Alias("yao.crypto.hmac", "crypto.Hmac")
|
||||
}
|
||||
|
||||
// ProcessHash yao.crypto.hash Crypto Hash
|
||||
// Args[0] string: the hash function name. MD4/MD5/SHA1/SHA224/SHA256/SHA384/SHA512/MD5SHA1/RIPEMD160/SHA3_224/SHA3_256/SHA3_384/SHA3_512/SHA512_224/SHA512_256/BLAKE2s_256/BLAKE2b_256/BLAKE2b_384/BLAKE2b_512
|
||||
// Args[1] string: value
|
||||
func ProcessHash(process *gou.Process) interface{} {
|
||||
func ProcessHash(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
typ := process.ArgsString(0)
|
||||
value := process.ArgsString(1)
|
||||
|
|
@ -38,7 +38,7 @@ func ProcessHash(process *gou.Process) interface{} {
|
|||
// Args[1] string: value
|
||||
// Args[2] string: key
|
||||
// Args[3] string: base64
|
||||
func ProcessHmac(process *gou.Process) interface{} {
|
||||
func ProcessHmac(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
typ := process.ArgsString(0)
|
||||
value := process.ArgsString(1)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ func TestMain(m *testing.M) {
|
|||
exitVal := m.Run()
|
||||
|
||||
// we can do clean up code here
|
||||
gou.KillPlugins()
|
||||
// gou.KillPlugins()
|
||||
|
||||
os.Exit(exitVal)
|
||||
}
|
||||
|
|
|
|||
173
engine/load.go
173
engine/load.go
|
|
@ -7,12 +7,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/yao/api"
|
||||
"github.com/yaoapp/yao/app"
|
||||
"github.com/yaoapp/yao/cert"
|
||||
"github.com/yaoapp/yao/chart"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/connector"
|
||||
"github.com/yaoapp/yao/flow"
|
||||
|
|
@ -20,40 +17,36 @@ import (
|
|||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/importer"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/page"
|
||||
"github.com/yaoapp/yao/plugin"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
"github.com/yaoapp/yao/schedule"
|
||||
"github.com/yaoapp/yao/script"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/socket"
|
||||
"github.com/yaoapp/yao/store"
|
||||
"github.com/yaoapp/yao/studio"
|
||||
"github.com/yaoapp/yao/table"
|
||||
"github.com/yaoapp/yao/task"
|
||||
"github.com/yaoapp/yao/websocket"
|
||||
"github.com/yaoapp/yao/widget"
|
||||
"github.com/yaoapp/yao/widgets"
|
||||
)
|
||||
|
||||
// Load 根据配置加载 API, FLow, Model, Plugin
|
||||
func Load(cfg config.Config) (err error) {
|
||||
defer func() { err = exception.Catch(recover()) }()
|
||||
|
||||
// Load Runtime
|
||||
err = runtime.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Runtime", err)
|
||||
}
|
||||
// // Load Runtime
|
||||
// err = runtime.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Runtime", err)
|
||||
// }
|
||||
|
||||
// 加载应用信息
|
||||
// 第一步: 加载应用信息
|
||||
app.Load(cfg)
|
||||
// // 加载应用信息
|
||||
// // 第一步: 加载应用信息
|
||||
// app.Load(cfg)
|
||||
|
||||
// 加密密钥函数
|
||||
gou.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey), "AES")
|
||||
gou.LoadCrypt(`{}`, "PASSWORD")
|
||||
// model.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey), "AES")
|
||||
// gou.LoadCrypt(`{}`, "PASSWORD")
|
||||
|
||||
// Load Certs
|
||||
err = cert.Load(cfg)
|
||||
|
|
@ -137,47 +130,47 @@ func Load(cfg config.Config) (err error) {
|
|||
printErr(cfg.Mode, "Plugin", err)
|
||||
}
|
||||
|
||||
// XGEN 1.0
|
||||
if share.App.XGen == "1.0" {
|
||||
// // XGEN 1.0
|
||||
// if share.App.XGen == "1.0" {
|
||||
|
||||
// SET XGEN_BASE
|
||||
// adminRoot := "yao"
|
||||
// if share.App.Optional != nil {
|
||||
// if root, has := share.App.Optional["adminRoot"]; has {
|
||||
// adminRoot = fmt.Sprintf("%v", root)
|
||||
// }
|
||||
// }
|
||||
// os.Setenv("XGEN_BASE", adminRoot)
|
||||
// // SET XGEN_BASE
|
||||
// // adminRoot := "yao"
|
||||
// // if share.App.Optional != nil {
|
||||
// // if root, has := share.App.Optional["adminRoot"]; has {
|
||||
// // adminRoot = fmt.Sprintf("%v", root)
|
||||
// // }
|
||||
// // }
|
||||
// // os.Setenv("XGEN_BASE", adminRoot)
|
||||
|
||||
// Load build-in widgets
|
||||
err = widgets.Load(cfg)
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Widgets", err)
|
||||
}
|
||||
// // Load build-in widgets
|
||||
// err = widgets.Load(cfg)
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Widgets", err)
|
||||
// }
|
||||
|
||||
delete(gou.APIs, "xiang.table")
|
||||
delete(gou.APIs, "xiang.page")
|
||||
delete(gou.APIs, "xiang.chart")
|
||||
delete(gou.APIs, "xiang.xiang")
|
||||
delete(gou.APIs, "xiang.user")
|
||||
delete(gou.APIs, "xiang.storage")
|
||||
// delete(gou.APIs, "xiang.table")
|
||||
// delete(gou.APIs, "xiang.page")
|
||||
// delete(gou.APIs, "xiang.chart")
|
||||
// delete(gou.APIs, "xiang.xiang")
|
||||
// delete(gou.APIs, "xiang.user")
|
||||
// delete(gou.APIs, "xiang.storage")
|
||||
|
||||
} else { // old version
|
||||
err = table.Load(cfg) // 加载数据表格 table
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Table", err)
|
||||
}
|
||||
// } else { // old version
|
||||
// err = table.Load(cfg) // 加载数据表格 table
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Table", err)
|
||||
// }
|
||||
|
||||
err = chart.Load(cfg) // 加载分析图表 chart
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Chart", err)
|
||||
}
|
||||
// err = chart.Load(cfg) // 加载分析图表 chart
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Chart", err)
|
||||
// }
|
||||
|
||||
err = page.Load(cfg) // 加载页面 page 忽略错误
|
||||
if err != nil {
|
||||
printErr(cfg.Mode, "Page", err)
|
||||
}
|
||||
}
|
||||
// err = page.Load(cfg) // 加载页面 page 忽略错误
|
||||
// if err != nil {
|
||||
// printErr(cfg.Mode, "Page", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
importer.Load(cfg) // 加载数据导入 imports
|
||||
|
||||
|
|
@ -223,51 +216,51 @@ func printErr(mode, widget string, err error) {
|
|||
|
||||
// Reload 根据配置重新加载 API, FLow, Model, Plugin
|
||||
func Reload(cfg config.Config) {
|
||||
gou.APIs = map[string]*gou.API{}
|
||||
gou.Models = map[string]*gou.Model{}
|
||||
gou.Flows = map[string]*gou.Flow{}
|
||||
gou.Plugins = map[string]*gou.Plugin{}
|
||||
// gou.APIs = map[string]*gou.API{}
|
||||
// gou.Models = map[string]*gou.Model{}
|
||||
// gou.Flows = map[string]*gou.Flow{}
|
||||
// gou.Plugins = map[string]*gou.Plugin{}
|
||||
Load(cfg)
|
||||
}
|
||||
|
||||
// LoadEngine 加载引擎的 API, Flow, Model 配置
|
||||
func LoadEngine(from ...string) {
|
||||
var scripts []share.Script
|
||||
if len(from) > 0 {
|
||||
scripts = share.GetFilesFS(from[0], ".json")
|
||||
} else {
|
||||
scripts = share.GetFilesBin("yao", ".json")
|
||||
}
|
||||
// var scripts []share.Script
|
||||
// if len(from) > 0 {
|
||||
// scripts = share.GetFilesFS(from[0], ".json")
|
||||
// } else {
|
||||
// scripts = share.GetFilesBin("yao", ".json")
|
||||
// }
|
||||
|
||||
if scripts == nil {
|
||||
exception.New("读取文件失败", 500, from).Throw()
|
||||
}
|
||||
// if scripts == nil {
|
||||
// exception.New("读取文件失败", 500, from).Throw()
|
||||
// }
|
||||
|
||||
if len(scripts) == 0 {
|
||||
exception.New("读取文件失败, 未找到任何可执行脚本", 500, from).Throw()
|
||||
}
|
||||
// if len(scripts) == 0 {
|
||||
// exception.New("读取文件失败, 未找到任何可执行脚本", 500, from).Throw()
|
||||
// }
|
||||
|
||||
// 加载 API, Flow, Models, Table, Chart, Screens
|
||||
for _, script := range scripts {
|
||||
switch script.Type {
|
||||
case "models":
|
||||
gou.LoadModel(string(script.Content), "xiang."+script.Name)
|
||||
break
|
||||
case "flows":
|
||||
gou.LoadFlow(string(script.Content), "xiang."+script.Name)
|
||||
break
|
||||
case "apis":
|
||||
gou.LoadAPI(string(script.Content), "xiang."+script.Name)
|
||||
break
|
||||
}
|
||||
}
|
||||
// // 加载 API, Flow, Models, Table, Chart, Screens
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "models":
|
||||
// gou.LoadModel(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "flows":
|
||||
// gou.LoadFlow(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// case "apis":
|
||||
// gou.LoadAPI(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
// 加载数据应用
|
||||
for _, script := range scripts {
|
||||
switch script.Type {
|
||||
case "tables":
|
||||
table.LoadTable(string(script.Content), "xiang."+script.Name)
|
||||
break
|
||||
}
|
||||
}
|
||||
// // 加载数据应用
|
||||
// for _, script := range scripts {
|
||||
// switch script.Type {
|
||||
// case "tables":
|
||||
// table.LoadTable(string(script.Content), "xiang."+script.Name)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,26 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/xfs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.main.Ping", processPing) // deprecated → utils.app.Ping @/utils/process.go
|
||||
gou.AliasProcess("xiang.main.Ping", "xiang.sys.Ping") // deprecated
|
||||
process.Register("xiang.main.Ping", processPing) // deprecated → utils.app.Ping @/utils/process.go
|
||||
process.Alias("xiang.main.Ping", "xiang.sys.Ping") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.main.FileContent", processFileContent) // deprecated
|
||||
gou.RegisterProcessHandler("xiang.main.AppFileContent", processAppFileContent) // deprecated
|
||||
process.Register("xiang.main.FileContent", processFileContent) // deprecated
|
||||
process.Register("xiang.main.AppFileContent", processAppFileContent) // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.main.Inspect", processInspect) // deprecated → utils.app.Inspect @/utils/process.go
|
||||
gou.AliasProcess("xiang.main.Inspect", "xiang.sys.Inspect") // deprecated
|
||||
process.Register("xiang.main.Inspect", processInspect) // deprecated → utils.app.Inspect @/utils/process.go
|
||||
process.Alias("xiang.main.Inspect", "xiang.sys.Inspect") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.main.Favicon", processFavicon) // deprecated
|
||||
process.Register("xiang.main.Favicon", processFavicon) // deprecated
|
||||
}
|
||||
|
||||
// processCreate 运行模型 MustCreate
|
||||
func processPing(process *gou.Process) interface{} {
|
||||
func processPing(process *process.Process) interface{} {
|
||||
res := map[string]interface{}{
|
||||
"engine": share.BUILDNAME,
|
||||
"version": share.VERSION,
|
||||
|
|
@ -33,37 +29,40 @@ func processPing(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// processInspect 返回系统信息
|
||||
func processInspect(process *gou.Process) interface{} {
|
||||
func processInspect(process *process.Process) interface{} {
|
||||
share.App.Icons.Set("favicon", "/api/xiang/favicon.ico")
|
||||
return share.App.Public()
|
||||
}
|
||||
|
||||
// processFavicon 运行模型 MustCreate
|
||||
func processFavicon(process *gou.Process) interface{} {
|
||||
return xfs.DecodeString(share.App.Icons.Get("png").(string))
|
||||
func processFavicon(process *process.Process) interface{} {
|
||||
// return xfs.DecodeString(share.App.Icons.Get("png").(string))
|
||||
return nil
|
||||
}
|
||||
|
||||
// processFileContent 返回文件内容
|
||||
func processFileContent(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
filename := process.ArgsString(0)
|
||||
encode := process.ArgsBool(1, true)
|
||||
content := xfs.Stor.MustReadFile(filename)
|
||||
if encode {
|
||||
return xfs.Encode(content)
|
||||
}
|
||||
return string(content)
|
||||
func processFileContent(process *process.Process) interface{} {
|
||||
// process.ValidateArgNums(2)
|
||||
// filename := process.ArgsString(0)
|
||||
// encode := process.ArgsBool(1, true)
|
||||
// content := xfs.Stor.MustReadFile(filename)
|
||||
// if encode {
|
||||
// return xfs.Encode(content)
|
||||
// }
|
||||
// return string(content)
|
||||
return nil
|
||||
}
|
||||
|
||||
// processAppFileContent 返回应用文件内容
|
||||
func processAppFileContent(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
fs := xfs.New(filepath.Join(config.Conf.Root, "data"))
|
||||
filename := process.ArgsString(0)
|
||||
encode := process.ArgsBool(1, true)
|
||||
content := fs.MustReadFile(filename)
|
||||
if encode {
|
||||
return xfs.Encode(content)
|
||||
}
|
||||
return string(content)
|
||||
func processAppFileContent(process *process.Process) interface{} {
|
||||
// process.ValidateArgNums(2)
|
||||
// fs := xfs.New(filepath.Join(config.Conf.Root, "data"))
|
||||
// filename := process.ArgsString(0)
|
||||
// encode := process.ArgsBool(1, true)
|
||||
// content := fs.MustReadFile(filename)
|
||||
// if encode {
|
||||
// return xfs.Encode(content)
|
||||
// }
|
||||
// return string(content)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,25 +4,25 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestProcessPing(t *testing.T) {
|
||||
process := gou.NewProcess("xiang.main.ping")
|
||||
process := process.New("xiang.main.ping")
|
||||
res, ok := processPing(process).(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, res["version"], share.VERSION)
|
||||
}
|
||||
|
||||
func TestProcessAliasPing(t *testing.T) {
|
||||
res, ok := gou.NewProcess("xiang.sys.Ping").Run().(map[string]interface{})
|
||||
res, ok := process.New("xiang.sys.Ping").Run().(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, res["version"], share.VERSION)
|
||||
}
|
||||
|
||||
func TestProcessInspect(t *testing.T) {
|
||||
res, ok := gou.NewProcess("xiang.sys.Inspect").Run().(share.AppInfo)
|
||||
res, ok := process.New("xiang.sys.Inspect").Run().(share.AppInfo)
|
||||
assert.True(t, ok)
|
||||
assert.NotNil(t, res.Version)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/yao/user"
|
||||
)
|
||||
|
||||
func TestUserAuth(t *testing.T) {
|
||||
|
||||
res := user.Auth("email", "xiang@iqka.com", "A123456p+")
|
||||
assert.True(t, res.Has("user"))
|
||||
assert.True(t, res.Has("token"))
|
||||
assert.True(t, res.Has("expires_at"))
|
||||
assert.Panics(t, func() {
|
||||
user.Auth("email", "xiang@iqka.com", "A123456p+22")
|
||||
})
|
||||
|
||||
res = user.Auth("mobile", "13900001111", "U123456p+")
|
||||
assert.True(t, res.Has("user"))
|
||||
assert.True(t, res.Has("token"))
|
||||
assert.True(t, res.Has("expires_at"))
|
||||
|
||||
assert.Panics(t, func() {
|
||||
user.Auth("email", "1390000111", "A123456p+22")
|
||||
})
|
||||
|
||||
}
|
||||
53
flow/flow.go
53
flow/flow.go
|
|
@ -1,58 +1,17 @@
|
|||
package flow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/flow"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load 加载业务逻辑编排
|
||||
func Load(cfg config.Config) error {
|
||||
if share.BUILDIN {
|
||||
return LoadBuildIn("flows", "")
|
||||
}
|
||||
return LoadFrom(filepath.Join(cfg.Root, "flows"), "")
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadFlowReturn(string(content), name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
exts := []string{"*.flow.yao", "*.flow.json", "*.flow.jsonc"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
_, err := flow.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}
|
||||
|
||||
// Load Script
|
||||
err = share.Walk(dir, ".js", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
flow := gou.SelectFlow(name)
|
||||
if flow != nil {
|
||||
script := share.ScriptName(filename)
|
||||
content := share.ReadFile(filename)
|
||||
flow.LoadScript(string(content), script)
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// LoadBuildIn 从制品中读取
|
||||
func LoadBuildIn(dir string, prefix string) error {
|
||||
return nil
|
||||
}, exts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,18 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/flow"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
runtime.Load(config.Conf)
|
||||
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 {
|
||||
for key := range flow.Flows {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 26, len(keys))
|
||||
|
|
|
|||
11
go.mod
11
go.mod
|
|
@ -3,7 +3,6 @@ module github.com/yaoapp/yao
|
|||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1286
|
||||
github.com/blang/semver v3.5.1+incompatible
|
||||
github.com/caarlos0/env/v6 v6.9.1
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
||||
|
|
@ -15,11 +14,10 @@ require (
|
|||
github.com/json-iterator/go v1.1.12
|
||||
github.com/mojocn/base64Captcha v1.3.5
|
||||
github.com/rhysd/go-github-selfupdate v1.2.3
|
||||
github.com/spf13/afero v1.6.0
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/stretchr/testify v1.7.1
|
||||
github.com/xuri/excelize/v2 v2.5.0
|
||||
github.com/yaoapp/gou v0.0.0-20211120135538-e5387704eb03
|
||||
github.com/yaoapp/gou v0.10.3
|
||||
github.com/yaoapp/kun v0.9.0
|
||||
github.com/yaoapp/xun v0.9.0
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||
|
|
@ -59,7 +57,6 @@ require (
|
|||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||
github.com/jmoiron/sqlx v1.3.4 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/leodido/go-urn v1.2.0 // indirect
|
||||
|
|
@ -81,7 +78,6 @@ require (
|
|||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/takama/daemon v1.0.0 // indirect
|
||||
github.com/tidwall/btree v1.1.0 // indirect
|
||||
github.com/tidwall/buntdb v1.2.9 // indirect
|
||||
github.com/tidwall/gjson v1.12.1 // indirect
|
||||
|
|
@ -109,17 +105,16 @@ require (
|
|||
google.golang.org/grpc v1.46.2 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
rogchap.com/v8go v0.7.0 // indirect
|
||||
rogchap.com/v8go v0.8.0 // indirect
|
||||
)
|
||||
|
||||
// go env -w GOPRIVATE=github.com/yaoapp/*
|
||||
|
||||
replace github.com/yaoapp/kun => ../kun // kun local
|
||||
|
||||
replace github.com/yaoapp/xun => ../xun // gou local
|
||||
replace github.com/yaoapp/xun => ../xun // xun local
|
||||
|
||||
replace github.com/yaoapp/gou => ../gou // gou local
|
||||
|
||||
|
|
|
|||
16
go.sum
16
go.sum
|
|
@ -41,8 +41,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
|||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkHBuFDA6DUhhse0IGJ7T5bemHyNILUjvOq4=
|
||||
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1286 h1:+Ah33S/QRnOFp4dM6VV2gYDbFu3Cj4HrRy1VpOhBzm8=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1286/go.mod h1:9CMdKNL3ynIGPpfTcdwTvIm8SGuAZYYC4jFVSSvE1YQ=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
|
|
@ -122,7 +120,6 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC
|
|||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
|
|
@ -199,7 +196,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
|||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
|
|
@ -241,20 +237,16 @@ github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h
|
|||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmoiron/sqlx v1.3.4 h1:wv+0IJZfL5z0uZoUjlpKgHkgaFSYD+r9CfrXjEXsO7w=
|
||||
github.com/jmoiron/sqlx v1.3.4/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
|
|
@ -335,7 +327,6 @@ github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj
|
|||
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
|
||||
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
|
||||
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
|
||||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
|
|
@ -346,11 +337,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
|
|||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
|
||||
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=
|
||||
|
|
@ -369,8 +357,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/takama/daemon v1.0.0 h1:XS3VLnFKmqw2Z7fQ/dHRarrVjdir9G3z7BEP8osjizQ=
|
||||
github.com/takama/daemon v1.0.0/go.mod h1:gKlhcjbqtBODg5v9H1nj5dU1a2j2GemtuWSNLD5rxOE=
|
||||
github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw=
|
||||
github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE=
|
||||
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
|
||||
|
|
@ -582,7 +568,6 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
@ -797,7 +782,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
|
|||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
// ProcessArrayPluck xiang.helper.ArrayPluck 将多个数据记录集合,合并为一个数据记录集合
|
||||
func ProcessArrayPluck(process *gou.Process) interface{} {
|
||||
func ProcessArrayPluck(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
columns := process.ArgsStrings(0)
|
||||
pluck := process.ArgsMap(1)
|
||||
|
|
@ -14,7 +14,7 @@ func ProcessArrayPluck(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArraySplit xiang.helper.ArraySplit 将多条数记录集合,分解为一个 columns:[]string 和 values: [][]interface{}
|
||||
func ProcessArraySplit(process *gou.Process) interface{} {
|
||||
func ProcessArraySplit(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
records := process.ArgsRecords(0)
|
||||
columns, values := ArraySplit(records)
|
||||
|
|
@ -25,7 +25,7 @@ func ProcessArraySplit(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayColumn xiang.helper.ArrayColumn 返回多条数据记录,指定字段数值。
|
||||
func ProcessArrayColumn(process *gou.Process) interface{} {
|
||||
func ProcessArrayColumn(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
records := process.ArgsRecords(0)
|
||||
name := process.ArgsString(1)
|
||||
|
|
@ -34,7 +34,7 @@ func ProcessArrayColumn(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayKeep xiang.helper.ArrayKeep 仅保留指定键名的数据
|
||||
func ProcessArrayKeep(process *gou.Process) interface{} {
|
||||
func ProcessArrayKeep(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
records := process.ArgsRecords(0)
|
||||
columns := process.ArgsStrings(1)
|
||||
|
|
@ -42,7 +42,7 @@ func ProcessArrayKeep(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayTree xiang.helper.ArrayTree 转换为属性结构
|
||||
func ProcessArrayTree(process *gou.Process) interface{} {
|
||||
func ProcessArrayTree(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
records := process.ArgsRecords(0)
|
||||
setting := process.ArgsMap(1)
|
||||
|
|
@ -50,7 +50,7 @@ func ProcessArrayTree(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayUnique xiang.helper.ArrayUnique 数组排重
|
||||
func ProcessArrayUnique(process *gou.Process) interface{} {
|
||||
func ProcessArrayUnique(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
if arr, ok := process.Args[0].([]interface{}); ok {
|
||||
return ArrayUnique(arr)
|
||||
|
|
@ -59,7 +59,7 @@ func ProcessArrayUnique(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayMapSet xiang.helper.ArrayMapSet 数组映射设定数值
|
||||
func ProcessArrayMapSet(process *gou.Process) interface{} {
|
||||
func ProcessArrayMapSet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
arr, ok := process.Args[0].([]map[string]interface{})
|
||||
if ok {
|
||||
|
|
@ -71,7 +71,7 @@ func ProcessArrayMapSet(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayIndexes xiang.helper.ArrayIndexes 返回数组索引。
|
||||
func ProcessArrayIndexes(process *gou.Process) interface{} {
|
||||
func ProcessArrayIndexes(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
records := process.ArgsArray(0)
|
||||
res := []int{}
|
||||
|
|
@ -82,7 +82,7 @@ func ProcessArrayIndexes(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessArrayGet xiang.helper.ArrayGet 返回指定索引数据
|
||||
func ProcessArrayGet(process *gou.Process) interface{} {
|
||||
func ProcessArrayGet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
records := process.ArgsArray(0)
|
||||
index := process.ArgsInt(1)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ func TestProcessArrayPluck(t *testing.T) {
|
|||
"计费": map[string]interface{}{"key": "city", "value": "计费种类", "items": []map[string]interface{}{{"city": "北京", "计费种类": 6}, {"city": "西安", "计费种类": 3}}},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.ArrayPluck", args...)
|
||||
process := process.New("xiang.helper.ArrayPluck", args...)
|
||||
response := ProcessArrayPluck(process)
|
||||
assert.NotNil(t, response)
|
||||
items, ok := response.([]map[string]interface{})
|
||||
|
|
@ -137,7 +137,7 @@ func TestProcessArraySplit(t *testing.T) {
|
|||
{"name": "世纪互联蓝云", "short_name": "上海蓝云"},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.ArraySplit", args...)
|
||||
process := process.New("xiang.helper.ArraySplit", args...)
|
||||
response := process.Run()
|
||||
assert.NotNil(t, response)
|
||||
res, ok := response.(map[string]interface{})
|
||||
|
|
@ -159,7 +159,7 @@ func TestProcessArrayUnique(t *testing.T) {
|
|||
args := []interface{}{
|
||||
[]interface{}{1, 2, 3, 3},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.ArrayUnique", args...)
|
||||
process := process.New("xiang.helper.ArrayUnique", args...)
|
||||
response := process.Run()
|
||||
assert.NotNil(t, response)
|
||||
res, ok := response.([]interface{})
|
||||
|
|
@ -171,7 +171,7 @@ func TestProcessArrayIndexes(t *testing.T) {
|
|||
args := []interface{}{
|
||||
[]interface{}{1, 2, 3, 3},
|
||||
}
|
||||
response := gou.NewProcess("xiang.helper.ArrayIndexes", args...).Run()
|
||||
response := process.New("xiang.helper.ArrayIndexes", args...).Run()
|
||||
assert.NotNil(t, response)
|
||||
res, ok := response.([]int)
|
||||
assert.True(t, ok)
|
||||
|
|
@ -180,10 +180,10 @@ func TestProcessArrayIndexes(t *testing.T) {
|
|||
|
||||
func TestProcessArrayGet(t *testing.T) {
|
||||
|
||||
response := gou.NewProcess("xiang.helper.ArrayGet", []interface{}{1, 2, 3, 3}, 2).Run()
|
||||
response := process.New("xiang.helper.ArrayGet", []interface{}{1, 2, 3, 3}, 2).Run()
|
||||
assert.Equal(t, 3, response)
|
||||
|
||||
response = gou.NewProcess("xiang.helper.ArrayGet", []interface{}{1, 2, 3, 3}, 4).Run()
|
||||
response = process.New("xiang.helper.ArrayGet", []interface{}{1, 2, 3, 3}, 4).Run()
|
||||
assert.Nil(t, response)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"image/color"
|
||||
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/log"
|
||||
|
|
@ -139,7 +139,7 @@ func captchaParseHexColorFast(s string) (c color.RGBA, err error) {
|
|||
}
|
||||
|
||||
// ProcessCaptchaValidate xiang.helper.CaptchaValidate 校验图形/音频验证码
|
||||
func ProcessCaptchaValidate(process *gou.Process) interface{} {
|
||||
func ProcessCaptchaValidate(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
id := process.ArgsString(0)
|
||||
code := process.ArgsString(1)
|
||||
|
|
@ -155,7 +155,7 @@ func ProcessCaptchaValidate(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessCaptcha xiang.helper.Captcha 校验图形/音频验证码
|
||||
func ProcessCaptcha(process *gou.Process) interface{} {
|
||||
func ProcessCaptcha(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
option := CaptchaOption{
|
||||
Width: any.Of(process.ArgsURLValue(0, "width", "240")).CInt(),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
|
|
@ -51,19 +51,19 @@ func TestProcessCaptcha(t *testing.T) {
|
|||
args := url.Values{}
|
||||
args.Add("type", "math")
|
||||
args.Add("lang", "zh")
|
||||
process := gou.NewProcess("xiang.helper.Captcha", args)
|
||||
res := process.Run().(maps.Map)
|
||||
p := process.New("xiang.helper.Captcha", args)
|
||||
res := p.Run().(maps.Map)
|
||||
assert.IsType(t, "string", res.Get("id"))
|
||||
assert.IsType(t, "string", res.Get("content"))
|
||||
|
||||
value := captchaStore.Get(res.Get("id").(string), false)
|
||||
process = gou.NewProcess("xiang.helper.CaptchaValidate", res.Get("id"), value)
|
||||
assert.True(t, process.Run().(bool))
|
||||
p = process.New("xiang.helper.CaptchaValidate", res.Get("id"), value)
|
||||
assert.True(t, p.Run().(bool))
|
||||
assert.Panics(t, func() {
|
||||
gou.NewProcess("xiang.helper.CaptchaValidate", res.Get("id"), "xxx").Run()
|
||||
process.New("xiang.helper.CaptchaValidate", res.Get("id"), "xxx").Run()
|
||||
})
|
||||
|
||||
assert.Panics(t, func() {
|
||||
gou.NewProcess("xiang.helper.CaptchaValidate", res.Get("id"), "").Run()
|
||||
process.New("xiang.helper.CaptchaValidate", res.Get("id"), "").Run()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package helper
|
|||
|
||||
import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ type CaseParam struct {
|
|||
func Case(params ...CaseParam) interface{} {
|
||||
for _, param := range params {
|
||||
if When(param.When) {
|
||||
return gou.NewProcess(param.Process, param.Args...).Run()
|
||||
return process.New(param.Process, param.Args...).Run()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -39,7 +39,7 @@ func CaseParamOf(v interface{}) CaseParam {
|
|||
}
|
||||
|
||||
// ProcessCase xiang.helper.Case Case条件判断
|
||||
func ProcessCase(process *gou.Process) interface{} {
|
||||
func ProcessCase(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
params := []CaseParam{}
|
||||
for _, v := range process.Args {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestCase(t *testing.T) {
|
||||
|
||||
gou.RegisterProcessHandler("xiang.unit.return", func(process *gou.Process) interface{} {
|
||||
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
|
||||
return process.Args
|
||||
})
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ func TestCase(t *testing.T) {
|
|||
|
||||
func TestProcessCase(t *testing.T) {
|
||||
|
||||
gou.RegisterProcessHandler("xiang.unit.return", func(process *gou.Process) interface{} {
|
||||
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
|
||||
return process.Args
|
||||
})
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ func TestProcessCase(t *testing.T) {
|
|||
"args": []interface{}{"foo"},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.Case", args...)
|
||||
process := process.New("xiang.helper.Case", args...)
|
||||
res := process.Run().([]interface{})
|
||||
assert.Equal(t, "world", res[0])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
// ProcessReturn xiang.helper.Return 返回数值
|
||||
func ProcessReturn(process *gou.Process) interface{} {
|
||||
func ProcessReturn(process *process.Process) interface{} {
|
||||
return process.Args
|
||||
}
|
||||
|
||||
// ProcessThrow xiang.helper.Throw 抛出异常
|
||||
func ProcessThrow(process *gou.Process) interface{} {
|
||||
func ProcessThrow(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
message := process.ArgsString(0)
|
||||
code := process.ArgsInt(1)
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
func TestProcessThrow(t *testing.T) {
|
||||
e := exception.New("Someting error", 500)
|
||||
assert.PanicsWithValue(t, *e, func() {
|
||||
gou.NewProcess("xiang.helper.Throw", "Someting error", 500).Run()
|
||||
process.New("xiang.helper.Throw", "Someting error", 500).Run()
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessReturn(t *testing.T) {
|
||||
v := gou.NewProcess("xiang.helper.Return", "hello", "world").Run().([]interface{})
|
||||
v := process.New("xiang.helper.Return", "hello", "world").Run().([]interface{})
|
||||
assert.Equal(t, "hello", v[0])
|
||||
assert.Equal(t, "world", v[1])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
// ProcessEnvGet xiang.helper.EnvGet 读取ENV
|
||||
func ProcessEnvGet(process *gou.Process) interface{} {
|
||||
func ProcessEnvGet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
name := process.ArgsString(0)
|
||||
return os.Getenv(name)
|
||||
}
|
||||
|
||||
// ProcessEnvSet xiang.helper.EnvSet 设置ENV
|
||||
func ProcessEnvSet(process *gou.Process) interface{} {
|
||||
func ProcessEnvSet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
value := process.ArgsString(1)
|
||||
|
|
@ -24,7 +24,7 @@ func ProcessEnvSet(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessEnvMultiGet xiang.helper.MultiGet 读取ENV
|
||||
func ProcessEnvMultiGet(process *gou.Process) interface{} {
|
||||
func ProcessEnvMultiGet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
res := map[string]string{}
|
||||
for i := range process.Args {
|
||||
|
|
@ -35,7 +35,7 @@ func ProcessEnvMultiGet(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessEnvMultiSet xiang.helper.MultiSet 设置ENV
|
||||
func ProcessEnvMultiSet(process *gou.Process) interface{} {
|
||||
func ProcessEnvMultiSet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
envs := process.ArgsMap(0)
|
||||
message := ""
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
func TestProcessEnv(t *testing.T) {
|
||||
err := gou.NewProcess("xiang.helper.EnvSet", "XIANG_UNIT_TEST", "FOO").Run()
|
||||
err := process.New("xiang.helper.EnvSet", "XIANG_UNIT_TEST", "FOO").Run()
|
||||
assert.Nil(t, err)
|
||||
test := gou.NewProcess("xiang.helper.EnvGet", "XIANG_UNIT_TEST").Run().(string)
|
||||
test := process.New("xiang.helper.EnvGet", "XIANG_UNIT_TEST").Run().(string)
|
||||
assert.Equal(t, "FOO", test)
|
||||
}
|
||||
|
||||
func TestProcessEnvMulti(t *testing.T) {
|
||||
err := gou.NewProcess("xiang.helper.EnvMultiSet", maps.Map{"XIANG_UNIT_TEST": "FOO", "XIANG_UNIT_TEST2": "BAR"}).Run()
|
||||
err := process.New("xiang.helper.EnvMultiSet", maps.Map{"XIANG_UNIT_TEST": "FOO", "XIANG_UNIT_TEST2": "BAR"}).Run()
|
||||
assert.Nil(t, err)
|
||||
test := gou.NewProcess("xiang.helper.EnvMultiGet", "XIANG_UNIT_TEST", "XIANG_UNIT_TEST2").Run().(map[string]string)
|
||||
test := process.New("xiang.helper.EnvMultiGet", "XIANG_UNIT_TEST", "XIANG_UNIT_TEST2").Run().(map[string]string)
|
||||
assert.Equal(t, "FOO", test["XIANG_UNIT_TEST"])
|
||||
assert.Equal(t, "BAR", test["XIANG_UNIT_TEST2"])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ package helper
|
|||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/log"
|
||||
)
|
||||
|
||||
// ProcessHexToString xiang.helper.HexToString
|
||||
func ProcessHexToString(process *gou.Process) interface{} {
|
||||
func ProcessHexToString(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
|
||||
switch process.Args[0].(type) {
|
||||
|
|
|
|||
|
|
@ -6,46 +6,43 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/flow"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestProcessHexToString(t *testing.T) {
|
||||
res, err := gou.NewProcess("xiang.helper.HexToString", []byte{0x0, 0x1}).Exec()
|
||||
res, err := process.New("xiang.helper.HexToString", []byte{0x0, 0x1}).Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "0001", res)
|
||||
|
||||
res, err = gou.NewProcess("xiang.helper.HexToString", string([]byte{0x0, 0x1})).Exec()
|
||||
res, err = process.New("xiang.helper.HexToString", string([]byte{0x0, 0x1})).Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "0001", res)
|
||||
|
||||
res, err = gou.NewProcess("xiang.helper.HexToString", 1024).Exec()
|
||||
res, err = process.New("xiang.helper.HexToString", 1024).Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestProcessHexToStringInFlow(t *testing.T) {
|
||||
testflow := path.Join(os.Getenv("YAO_DEV"), "tests", "flows", "helper")
|
||||
flow.LoadFrom(testflow, "helper.")
|
||||
// testflow := path.Join(os.Getenv("YAO_DEV"), "tests", "flows", "helper")
|
||||
// flow.Load(testflow, "helper.")
|
||||
|
||||
res, err := gou.NewProcess("flows.helper.HexToString").Exec()
|
||||
res, err := process.New("flows.helper.HexToString").Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "6162", res) // ab
|
||||
}
|
||||
|
||||
func TestProcessHexToStringInScript(t *testing.T) {
|
||||
runtime.Load(config.Conf)
|
||||
|
||||
testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts")
|
||||
share.LoadFrom(testscirpt)
|
||||
|
||||
res, err := gou.NewProcess("scripts.helper.HexToStringString").Exec()
|
||||
res, err := process.New("scripts.helper.HexToStringString").Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "6162", res) // ab
|
||||
|
||||
res, err = gou.NewProcess("scripts.helper.HexToStringBytes", []byte{0x0, 0x1}).Exec()
|
||||
res, err = process.New("scripts.helper.HexToStringBytes", []byte{0x0, 0x1}).Exec()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "0001", res) // []byte{0x0, 0x1}
|
||||
}
|
||||
|
|
@ -54,7 +51,7 @@ func TestProcessBufferInScript(t *testing.T) {
|
|||
testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts")
|
||||
share.LoadFrom(testscirpt)
|
||||
|
||||
res, err := gou.NewProcess("scripts.helper.Buffer").Exec()
|
||||
res, err := process.New("scripts.helper.Buffer").Exec()
|
||||
assert.Nil(t, err)
|
||||
|
||||
str, ok := res.(string)
|
||||
|
|
|
|||
10
helper/if.go
10
helper/if.go
|
|
@ -1,19 +1,21 @@
|
|||
package helper
|
||||
|
||||
import "github.com/yaoapp/gou"
|
||||
import (
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
// IF 条件判断
|
||||
func IF(param CaseParam, paramElse ...CaseParam) interface{} {
|
||||
if When(param.When) {
|
||||
return gou.NewProcess(param.Process, param.Args...).Run()
|
||||
return process.New(param.Process, param.Args...).Run()
|
||||
} else if len(paramElse) > 0 && When(paramElse[0].When) {
|
||||
return gou.NewProcess(paramElse[0].Process, paramElse[0].Args...).Run()
|
||||
return process.New(paramElse[0].Process, paramElse[0].Args...).Run()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessIF xiang.helper.IF IF条件判断
|
||||
func ProcessIF(process *gou.Process) interface{} {
|
||||
func ProcessIF(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
params := []CaseParam{}
|
||||
for _, v := range process.Args {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestIF(t *testing.T) {
|
||||
|
||||
gou.RegisterProcessHandler("xiang.unit.return", func(process *gou.Process) interface{} {
|
||||
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
|
||||
return process.Args
|
||||
})
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ func TestIF(t *testing.T) {
|
|||
|
||||
func TestProcessIF(t *testing.T) {
|
||||
|
||||
gou.RegisterProcessHandler("xiang.unit.return", func(process *gou.Process) interface{} {
|
||||
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
|
||||
return process.Args
|
||||
})
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ func TestProcessIF(t *testing.T) {
|
|||
"args": []interface{}{"foo"},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.IF", args...)
|
||||
process := process.New("xiang.helper.IF", args...)
|
||||
res := process.Run().([]interface{})
|
||||
assert.Equal(t, "world", res[0])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/gou/session"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
|
|
@ -119,7 +119,7 @@ func JwtMake(id int, data map[string]interface{}, option map[string]interface{},
|
|||
}
|
||||
|
||||
// ProcessJwtMake xiang.helper.JwtMake 生成JWT
|
||||
func ProcessJwtMake(process *gou.Process) interface{} {
|
||||
func ProcessJwtMake(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
id := process.ArgsInt(0)
|
||||
data := process.ArgsMap(1)
|
||||
|
|
@ -131,7 +131,7 @@ func ProcessJwtMake(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessJwtValidate xiang.helper.JwtValidate 校验JWT
|
||||
func ProcessJwtValidate(process *gou.Process) interface{} {
|
||||
func ProcessJwtValidate(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
tokenString := process.ArgsString(0)
|
||||
return JwtValidate(tokenString)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestJwt(t *testing.T) {
|
||||
|
|
@ -26,13 +26,13 @@ func TestProcessJwt(t *testing.T) {
|
|||
data := map[string]interface{}{"hello": "world", "id": 1}
|
||||
option := map[string]interface{}{"subject": "Unit Test", "audience": "Test", "issuer": "UnitTest", "timeout": 1, "sid": ""}
|
||||
args := []interface{}{1, data, option}
|
||||
process := gou.NewProcess("xiang.helper.JwtMake", args...)
|
||||
token := process.Run().(JwtToken)
|
||||
p := process.New("xiang.helper.JwtMake", args...)
|
||||
token := p.Run().(JwtToken)
|
||||
tokenString := token.Token
|
||||
res := gou.NewProcess("xiang.helper.JwtValidate", tokenString).Run().(*JwtClaims)
|
||||
res := process.New("xiang.helper.JwtValidate", tokenString).Run().(*JwtClaims)
|
||||
assert.Equal(t, float64(1), res.Data["id"])
|
||||
assert.Equal(t, "world", res.Data["hello"])
|
||||
assert.Equal(t, "UnitTest", res.Issuer)
|
||||
time.Sleep(2 * time.Second)
|
||||
assert.Panics(t, func() { gou.NewProcess("xiang.helper.JwtValidate", tokenString).Run() })
|
||||
assert.Panics(t, func() { process.New("xiang.helper.JwtValidate", tokenString).Run() })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,25 +3,25 @@ package helper
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
// ProcessMapValues xiang.helper.MapValues 返回映射表的数值
|
||||
func ProcessMapValues(process *gou.Process) interface{} {
|
||||
func ProcessMapValues(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
record := process.ArgsMap(0)
|
||||
return MapValues(record)
|
||||
}
|
||||
|
||||
// ProcessMapKeys xiang.helper.MapKeys 返回映射表的键
|
||||
func ProcessMapKeys(process *gou.Process) interface{} {
|
||||
func ProcessMapKeys(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
record := process.ArgsMap(0)
|
||||
return MapKeys(record)
|
||||
}
|
||||
|
||||
// ProcessMapGet xiang.helper.MapGet 返回映射表给定键的值
|
||||
func ProcessMapGet(process *gou.Process) interface{} {
|
||||
func ProcessMapGet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
record := process.ArgsMap(0)
|
||||
key := process.ArgsString(1)
|
||||
|
|
@ -29,7 +29,7 @@ func ProcessMapGet(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessMapSet xiang.helper.MapSet 设定键值,返回映射表给定键的值
|
||||
func ProcessMapSet(process *gou.Process) interface{} {
|
||||
func ProcessMapSet(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
record := process.ArgsMap(0)
|
||||
key := process.ArgsString(1)
|
||||
|
|
@ -38,7 +38,7 @@ func ProcessMapSet(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessMapDel xiang.helper.MapDel 删除给定键, 返回映射表
|
||||
func ProcessMapDel(process *gou.Process) interface{} {
|
||||
func ProcessMapDel(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
record := process.ArgsMap(0)
|
||||
key := process.ArgsString(1)
|
||||
|
|
@ -46,7 +46,7 @@ func ProcessMapDel(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessMapMultiDel xiang.helper.MapMultiDel 删除一组给定键, 返回映射表
|
||||
func ProcessMapMultiDel(process *gou.Process) interface{} {
|
||||
func ProcessMapMultiDel(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
record := process.ArgsMap(0)
|
||||
keys := []string{}
|
||||
|
|
@ -57,7 +57,7 @@ func ProcessMapMultiDel(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessMapToArray xiang.helper.MapToArray 映射转换为 KeyValue 数组
|
||||
func ProcessMapToArray(process *gou.Process) interface{} {
|
||||
func ProcessMapToArray(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
m := process.ArgsMap(0)
|
||||
res := []map[string]interface{}{}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestProcessMapDel(t *testing.T) {
|
||||
|
|
@ -12,7 +12,7 @@ func TestProcessMapDel(t *testing.T) {
|
|||
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
|
||||
"bar",
|
||||
}
|
||||
new := gou.NewProcess("xiang.helper.MapDel", args...).Run().(map[string]interface{})
|
||||
new := process.New("xiang.helper.MapDel", args...).Run().(map[string]interface{})
|
||||
_, has := new["bar"]
|
||||
assert.False(t, has)
|
||||
assert.Equal(t, "Value1", new["foo"])
|
||||
|
|
@ -24,11 +24,11 @@ func TestProcessGetSet(t *testing.T) {
|
|||
"bar",
|
||||
"Value2",
|
||||
}
|
||||
new := gou.NewProcess("xiang.helper.MapSet", args...).Run().(map[string]interface{})
|
||||
new := process.New("xiang.helper.MapSet", args...).Run().(map[string]interface{})
|
||||
assert.Equal(t, "Value1", new["foo"])
|
||||
assert.Equal(t, "Value2", new["bar"])
|
||||
|
||||
bar := gou.NewProcess("xiang.helper.MapGet", new, "bar").Run().(string)
|
||||
bar := process.New("xiang.helper.MapGet", new, "bar").Run().(string)
|
||||
assert.Equal(t, "Value2", bar)
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ func TestProcessMapKeys(t *testing.T) {
|
|||
args := []interface{}{
|
||||
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
|
||||
}
|
||||
keys := gou.NewProcess("xiang.helper.MapKeys", args...).Run().([]string)
|
||||
keys := process.New("xiang.helper.MapKeys", args...).Run().([]string)
|
||||
assert.Contains(t, keys, "foo")
|
||||
assert.Contains(t, keys, "bar")
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ func TestProcessMapValues(t *testing.T) {
|
|||
args := []interface{}{
|
||||
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
|
||||
}
|
||||
values := gou.NewProcess("xiang.helper.MapValues", args...).Run().([]interface{})
|
||||
values := process.New("xiang.helper.MapValues", args...).Run().([]interface{})
|
||||
assert.Contains(t, values, "Value1")
|
||||
assert.Contains(t, values, "Value2")
|
||||
}
|
||||
|
|
@ -56,14 +56,14 @@ func TestProcessMapMultiDel(t *testing.T) {
|
|||
"foo",
|
||||
"bar",
|
||||
}
|
||||
new := gou.NewProcess("xiang.helper.MapMultiDel", args...).Run().(map[string]interface{})
|
||||
new := process.New("xiang.helper.MapMultiDel", args...).Run().(map[string]interface{})
|
||||
assert.Nil(t, new["foo"])
|
||||
assert.Nil(t, new["bar"])
|
||||
}
|
||||
|
||||
func TestProcessMapToArray(t *testing.T) {
|
||||
|
||||
arr := gou.NewProcess("xiang.helper.MapToArray", map[string]interface{}{
|
||||
arr := process.New("xiang.helper.MapToArray", map[string]interface{}{
|
||||
"foo": "Value1",
|
||||
"bar": "Value2",
|
||||
}).Run().([]map[string]interface{})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
|
@ -17,7 +17,7 @@ func PasswordValidate(password string, passwordHash string) bool {
|
|||
}
|
||||
|
||||
// ProcessPasswordValidate xiang.helper.PasswordValidate 校验密码
|
||||
func ProcessPasswordValidate(process *gou.Process) interface{} {
|
||||
func ProcessPasswordValidate(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
return PasswordValidate(process.ArgsString(0), process.ArgsString(1))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestPassword(t *testing.T) {
|
||||
|
|
@ -18,13 +18,13 @@ func TestProcessPassword(t *testing.T) {
|
|||
pwd := "U123456p+"
|
||||
hash := "$2a$04$TS/rWBs66jADjQl8fa.w..ivkNAjH8d4sI1OPGvEB9Leed6EpzIF2"
|
||||
args := []interface{}{pwd, hash}
|
||||
process := gou.NewProcess("xiang.helper.PasswordValidate", args...)
|
||||
res := process.Run()
|
||||
p := process.New("xiang.helper.PasswordValidate", args...)
|
||||
res := p.Run()
|
||||
assert.True(t, res.(bool))
|
||||
|
||||
args = []interface{}{pwd, "123456"}
|
||||
process = gou.NewProcess("xiang.helper.PasswordValidate", args...)
|
||||
p = process.New("xiang.helper.PasswordValidate", args...)
|
||||
assert.Panics(t, func() {
|
||||
process.Run()
|
||||
p.Run()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,89 +3,89 @@ package helper
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayGet", ProcessArrayGet) // deprecated → utils.arr.Get @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayIndexes", ProcessArrayIndexes) // deprecated → utils.arr.Indexes @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayPluck", ProcessArrayPluck) // deprecated → utils.arr.Pluck @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArraySplit", ProcessArraySplit) // deprecated → utils.arr.Split @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayColumn", ProcessArrayColumn) // deprecated → utils.arr.Column @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayKeep", ProcessArrayKeep) // deprecated → utils.arr.Keep @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayTree", ProcessArrayTree) // deprecated → utils.arr.Tree @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayUnique", ProcessArrayUnique) // deprecated → utils.arr.Unique @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayMapSet", ProcessArrayMapSet) // deprecated → utils.arr.MapSet @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayGet", ProcessArrayGet) // deprecated → utils.arr.Get @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayIndexes", ProcessArrayIndexes) // deprecated → utils.arr.Indexes @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayPluck", ProcessArrayPluck) // deprecated → utils.arr.Pluck @/utils/process.go
|
||||
process.Register("xiang.helper.ArraySplit", ProcessArraySplit) // deprecated → utils.arr.Split @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayColumn", ProcessArrayColumn) // deprecated → utils.arr.Column @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayKeep", ProcessArrayKeep) // deprecated → utils.arr.Keep @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayTree", ProcessArrayTree) // deprecated → utils.arr.Tree @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayUnique", ProcessArrayUnique) // deprecated → utils.arr.Unique @/utils/process.go
|
||||
process.Register("xiang.helper.ArrayMapSet", ProcessArrayMapSet) // deprecated → utils.arr.MapSet @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.MapKeys", ProcessMapKeys) // deprecated → utils.map.Keys @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapValues", ProcessMapValues) // deprecated → utils.map.Values @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapToArray", ProcessMapToArray) // deprecated → utils.map.Array @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapGet", ProcessMapGet) // deprecated → utils.map.Get @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapSet", ProcessMapSet) // deprecated → utils.map.Set @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapDel", ProcessMapDel) // deprecated → utils.map.Del @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.MapMultiDel", ProcessMapMultiDel) // deprecated → utils.map.DelMany @/utils/process.go
|
||||
process.Register("xiang.helper.MapKeys", ProcessMapKeys) // deprecated → utils.map.Keys @/utils/process.go
|
||||
process.Register("xiang.helper.MapValues", ProcessMapValues) // deprecated → utils.map.Values @/utils/process.go
|
||||
process.Register("xiang.helper.MapToArray", ProcessMapToArray) // deprecated → utils.map.Array @/utils/process.go
|
||||
process.Register("xiang.helper.MapGet", ProcessMapGet) // deprecated → utils.map.Get @/utils/process.go
|
||||
process.Register("xiang.helper.MapSet", ProcessMapSet) // deprecated → utils.map.Set @/utils/process.go
|
||||
process.Register("xiang.helper.MapDel", ProcessMapDel) // deprecated → utils.map.Del @/utils/process.go
|
||||
process.Register("xiang.helper.MapMultiDel", ProcessMapMultiDel) // deprecated → utils.map.DelMany @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.HexToString", ProcessHexToString) // deprecated
|
||||
process.Register("xiang.helper.HexToString", ProcessHexToString) // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.StrConcat", ProcessStrConcat) // deprecated → utils.str.Concat @/utils/process.go
|
||||
process.Register("xiang.helper.StrConcat", ProcessStrConcat) // deprecated → utils.str.Concat @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.Captcha", ProcessCaptcha) // deprecated → utils.captcha.Make @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.CaptchaValidate", ProcessCaptchaValidate) // deprecated → utils.captcha.Verify @/utils/process.go
|
||||
process.Register("xiang.helper.Captcha", ProcessCaptcha) // deprecated → utils.captcha.Make @/utils/process.go
|
||||
process.Register("xiang.helper.CaptchaValidate", ProcessCaptchaValidate) // deprecated → utils.captcha.Verify @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.PasswordValidate", ProcessPasswordValidate) // deprecated → utils.pwd.Verify @/utils/process.go
|
||||
process.Register("xiang.helper.PasswordValidate", ProcessPasswordValidate) // deprecated → utils.pwd.Verify @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.JwtMake", ProcessJwtMake) // deprecated → utils.jwt.Make @/utils/process.go
|
||||
gou.RegisterProcessHandler("xiang.helper.JwtValidate", ProcessJwtValidate) // deprecated → utils.jwt.Verify @/utils/process.go
|
||||
process.Register("xiang.helper.JwtMake", ProcessJwtMake) // deprecated → utils.jwt.Make @/utils/process.go
|
||||
process.Register("xiang.helper.JwtValidate", ProcessJwtValidate) // deprecated → utils.jwt.Verify @/utils/process.go
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.For", ProcessFor) // deprecated → utils.flow.For @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.For", "xiang.flow.For") // deprecated
|
||||
gou.RegisterProcessHandler("xiang.helper.Each", ProcessEach) // deprecated → utils.flow.Each @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.Each", "xiang.flow.Each") // deprecated
|
||||
gou.RegisterProcessHandler("xiang.helper.Case", ProcessCase) // deprecated → utils.flow.Case @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.Case", "xiang.flow.Case") // deprecated
|
||||
gou.RegisterProcessHandler("xiang.helper.IF", ProcessIF) // deprecated → utils.flow.IF @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.IF", "xiang.flow.IF") // deprecated
|
||||
gou.RegisterProcessHandler("xiang.helper.Throw", ProcessThrow) // deprecated → utils.flow.Throw @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.Throw", "xiang.flow.Throw") // deprecated
|
||||
gou.RegisterProcessHandler("xiang.helper.Return", ProcessReturn) // deprecated → utils.flow.Return @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.Return", "xiang.flow.Return") // deprecated
|
||||
process.Register("xiang.helper.For", ProcessFor) // deprecated → utils.flow.For @/utils/process.go
|
||||
process.Alias("xiang.helper.For", "xiang.flow.For") // deprecated
|
||||
process.Register("xiang.helper.Each", ProcessEach) // deprecated → utils.flow.Each @/utils/process.go
|
||||
process.Alias("xiang.helper.Each", "xiang.flow.Each") // deprecated
|
||||
process.Register("xiang.helper.Case", ProcessCase) // deprecated → utils.flow.Case @/utils/process.go
|
||||
process.Alias("xiang.helper.Case", "xiang.flow.Case") // deprecated
|
||||
process.Register("xiang.helper.IF", ProcessIF) // deprecated → utils.flow.IF @/utils/process.go
|
||||
process.Alias("xiang.helper.IF", "xiang.flow.IF") // deprecated
|
||||
process.Register("xiang.helper.Throw", ProcessThrow) // deprecated → utils.flow.Throw @/utils/process.go
|
||||
process.Alias("xiang.helper.Throw", "xiang.flow.Throw") // deprecated
|
||||
process.Register("xiang.helper.Return", ProcessReturn) // deprecated → utils.flow.Return @/utils/process.go
|
||||
process.Alias("xiang.helper.Return", "xiang.flow.Return") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvSet", ProcessEnvSet) // deprecated → utils.env.Set @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.EnvSet", "xiang.env.Set") // deprecated
|
||||
gou.AliasProcess("xiang.helper.EnvSet", "yao.env.Set") // deprecated
|
||||
process.Register("xiang.helper.EnvSet", ProcessEnvSet) // deprecated → utils.env.Set @/utils/process.go
|
||||
process.Alias("xiang.helper.EnvSet", "xiang.env.Set") // deprecated
|
||||
process.Alias("xiang.helper.EnvSet", "yao.env.Set") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvGet", ProcessEnvGet) // deprecated → utils.env.Get @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.EnvGet", "xiang.env.Get") // deprecated
|
||||
gou.AliasProcess("xiang.helper.EnvGet", "yao.env.Get") // deprecated
|
||||
process.Register("xiang.helper.EnvGet", ProcessEnvGet) // deprecated → utils.env.Get @/utils/process.go
|
||||
process.Alias("xiang.helper.EnvGet", "xiang.env.Get") // deprecated
|
||||
process.Alias("xiang.helper.EnvGet", "yao.env.Get") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvMultiSet", ProcessEnvMultiSet) // deprecated → utils.env.SetMany @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.EnvMultiSet", "xiang.env.MultiSet") // deprecated
|
||||
gou.AliasProcess("xiang.helper.EnvMultiSet", "yao.env.MultiSet") // deprecated
|
||||
process.Register("xiang.helper.EnvMultiSet", ProcessEnvMultiSet) // deprecated → utils.env.SetMany @/utils/process.go
|
||||
process.Alias("xiang.helper.EnvMultiSet", "xiang.env.MultiSet") // deprecated
|
||||
process.Alias("xiang.helper.EnvMultiSet", "yao.env.MultiSet") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvMultiGet", ProcessEnvMultiGet) // deprecated → utils.env.GetMany @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.EnvMultiGet", "xiang.env.MultiGet") // deprecated
|
||||
gou.AliasProcess("xiang.helper.EnvMultiGet", "yao.env.MultiGet") // deprecated
|
||||
process.Register("xiang.helper.EnvMultiGet", ProcessEnvMultiGet) // deprecated → utils.env.GetMany @/utils/process.go
|
||||
process.Alias("xiang.helper.EnvMultiGet", "xiang.env.MultiGet") // deprecated
|
||||
process.Alias("xiang.helper.EnvMultiGet", "yao.env.MultiGet") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.Print", ProcessPrint) // deprecated → utils.fmt.Println @/utils/process.go
|
||||
gou.AliasProcess("xiang.helper.Print", "xiang.sys.Print") // deprecated
|
||||
process.Register("xiang.helper.Print", ProcessPrint) // deprecated → utils.fmt.Println @/utils/process.go
|
||||
process.Alias("xiang.helper.Print", "xiang.sys.Print") // deprecated
|
||||
|
||||
gou.RegisterProcessHandler("xiang.flow.Sleep", ProcessSleep) // deprecated → utils.time.Sleep @/utils/process.go
|
||||
gou.AliasProcess("xiang.flow.Sleep", "xiang.sys.Sleep") // deprecated
|
||||
gou.AliasProcess("xiang.flow.Sleep", "yao.sys.Sleep") // deprecated
|
||||
process.Register("xiang.flow.Sleep", ProcessSleep) // deprecated → utils.time.Sleep @/utils/process.go
|
||||
process.Alias("xiang.flow.Sleep", "xiang.sys.Sleep") // deprecated
|
||||
process.Alias("xiang.flow.Sleep", "yao.sys.Sleep") // deprecated
|
||||
|
||||
}
|
||||
|
||||
// ProcessPrint xiang.helper.Print 打印语句
|
||||
func ProcessPrint(process *gou.Process) interface{} {
|
||||
func ProcessPrint(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
utils.Dump(process.Args...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessSleep xiang.flow.Sleep 等待
|
||||
func ProcessSleep(process *gou.Process) interface{} {
|
||||
func ProcessSleep(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
ms := process.ArgsInt(0)
|
||||
time.Sleep(time.Duration((ms * int(time.Millisecond))))
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"regexp"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/query/share"
|
||||
"github.com/yaoapp/gou/helper"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
|
@ -69,14 +69,14 @@ func For(from int, to int, p Process) {
|
|||
"value": i,
|
||||
}
|
||||
args := bindArgs(p.Args, bindings)
|
||||
gou.NewProcess(p.Process, args...).Run()
|
||||
process.New(p.Process, args...).Run()
|
||||
}
|
||||
}
|
||||
|
||||
func bindArgs(args []interface{}, bindings map[string]interface{}) []interface{} {
|
||||
new := []interface{}{}
|
||||
for i := range args {
|
||||
new = append(new, share.Bind(args[i], bindings, reVar))
|
||||
new = append(new, helper.Bind(args[i], bindings, reVar))
|
||||
}
|
||||
return new
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func rangeString(v string, p Process) {
|
|||
"value": value,
|
||||
}
|
||||
args := bindArgs(p.Args, bindings)
|
||||
gou.NewProcess(p.Process, args...).Run()
|
||||
process.New(p.Process, args...).Run()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ func rangeMap(v map[string]interface{}, p Process) {
|
|||
"value": value,
|
||||
}
|
||||
args := bindArgs(p.Args, bindings)
|
||||
gou.NewProcess(p.Process, args...).Run()
|
||||
process.New(p.Process, args...).Run()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ func rangeArray(v []interface{}, p Process) {
|
|||
"value": value,
|
||||
}
|
||||
args := bindArgs(p.Args, bindings)
|
||||
gou.NewProcess(p.Process, args...).Run()
|
||||
process.New(p.Process, args...).Run()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ func ProcessOf(v map[string]interface{}) Process {
|
|||
}
|
||||
|
||||
// ProcessEach xiang.helper.Each 循环过程控制
|
||||
func ProcessEach(process *gou.Process) interface{} {
|
||||
func ProcessEach(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
v := process.Args[0]
|
||||
p := ProcessOf(process.ArgsMap(1))
|
||||
|
|
@ -150,7 +150,7 @@ func ProcessEach(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// ProcessFor xiang.helper.For 循环过程控制
|
||||
func ProcessFor(process *gou.Process) interface{} {
|
||||
func ProcessFor(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
from := process.ArgsInt(0)
|
||||
to := process.ArgsInt(1)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package helper
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
// ProcessStrConcat xiang.helper.StrConcat 连接字符串
|
||||
func ProcessStrConcat(process *gou.Process) interface{} {
|
||||
func ProcessStrConcat(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
res := ""
|
||||
for i := range process.Args {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestProcessStrConcat(t *testing.T) {
|
||||
res := gou.NewProcess("xiang.helper.StrConcat", "FOO", 20, "BAR").Run().(string)
|
||||
res := process.New("xiang.helper.StrConcat", "FOO", 20, "BAR").Run().(string)
|
||||
assert.Equal(t, "FOO20BAR", res)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/log"
|
||||
|
|
@ -17,32 +17,30 @@ import (
|
|||
"github.com/yaoapp/yao/importer/from"
|
||||
"github.com/yaoapp/yao/importer/xlsx"
|
||||
"github.com/yaoapp/yao/share"
|
||||
"github.com/yaoapp/yao/xfs"
|
||||
)
|
||||
|
||||
// Importers 导入器
|
||||
var Importers = map[string]*Importer{}
|
||||
|
||||
// Load 加载导入器
|
||||
func Load(cfg config.Config) {
|
||||
LoadFrom(filepath.Join(cfg.Root, "imports"), "")
|
||||
}
|
||||
func Load(cfg config.Config) error {
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) {
|
||||
if share.DirNotExists(dir) {
|
||||
return
|
||||
}
|
||||
share.Walk(dir, ".json", func(root, filename string) {
|
||||
var importer Importer
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
err := jsoniter.Unmarshal(content, &importer)
|
||||
id := share.ID(root, file)
|
||||
data, err := application.App.Read(file)
|
||||
if err != nil {
|
||||
exception.New("%s 导入配置错误. %s", 400, name, err.Error()).Ctx(filename).Throw()
|
||||
return err
|
||||
}
|
||||
Importers[name] = &importer
|
||||
})
|
||||
|
||||
var importer Importer
|
||||
err = application.Parse(file, data, &importer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s 导入配置错误. %s", id, err.Error())
|
||||
}
|
||||
Importers[id] = &importer
|
||||
|
||||
return err
|
||||
}, config.DSLExtensions...)
|
||||
}
|
||||
|
||||
// Select 选择已加载导入器
|
||||
|
|
@ -59,12 +57,13 @@ func Open(name string) from.Source {
|
|||
ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(name), "."))
|
||||
switch ext {
|
||||
case "xlsx":
|
||||
// Refector *****
|
||||
// fullpath := name
|
||||
fullpath := filepath.Join(xfs.Stor.Root, name)
|
||||
// fullpath := filepath.Join(xfs.Stor.Root, name)
|
||||
// if !strings.HasPrefix(fullpath, "/") {
|
||||
// fullpath = filepath.Join(xfs.Stor.Root, name)
|
||||
// }
|
||||
return xlsx.Open(fullpath)
|
||||
return xlsx.Open(name)
|
||||
}
|
||||
exception.New("暂不支持: %s 文件导入", 400, ext).Throw()
|
||||
return nil
|
||||
|
|
@ -169,7 +168,7 @@ func (imp *Importer) DataClean(data [][]interface{}, bindings []*Binding) ([]str
|
|||
|
||||
// DataValidate 数值校验
|
||||
func DataValidate(row []interface{}, value interface{}, rule string) ([]interface{}, bool) {
|
||||
process, err := gou.ProcessOf(rule, value, row)
|
||||
process, err := process.Of(rule, value, row)
|
||||
if err != nil {
|
||||
log.With(log.F{"rule": rule, "row": row}).Error("DataValidate: %s", err.Error())
|
||||
return row, true
|
||||
|
|
@ -405,7 +404,7 @@ func (imp *Importer) Run(src from.Source, mapping *Mapping) interface{} {
|
|||
length := len(data)
|
||||
total = total + length
|
||||
columns, data := imp.DataClean(data, mapping.Columns)
|
||||
process, err := gou.ProcessOf(imp.Process, columns, data, id, page)
|
||||
process, err := process.Of(imp.Process, columns, data, id, page)
|
||||
if err != nil {
|
||||
failed = failed + length
|
||||
log.With(log.F{"line": line}).Error("导入失败: %s", err.Error())
|
||||
|
|
@ -444,7 +443,7 @@ func (imp *Importer) Run(src from.Source, mapping *Mapping) interface{} {
|
|||
}
|
||||
|
||||
if imp.Output != "" {
|
||||
res, err := gou.NewProcess(imp.Output, output).WithSID(imp.Sid).Exec()
|
||||
res, err := process.New(imp.Output, output).WithSID(imp.Sid).Exec()
|
||||
if err != nil {
|
||||
log.With(log.F{"output": imp.Output}).Error(err.Error())
|
||||
return output
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
LoadFrom("not a path", "404.")
|
||||
assert.IsType(t, &Importer{}, Select("order"))
|
||||
}
|
||||
func TestFingerprintSimple(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -7,13 +7,11 @@ import (
|
|||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
"github.com/yaoapp/yao/script"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
runtime.Load(config.Conf)
|
||||
share.DBConnect(config.Conf.DB)
|
||||
model.Load(config.Conf)
|
||||
query.Load(config.Conf)
|
||||
|
|
|
|||
|
|
@ -2,31 +2,31 @@ package importer
|
|||
|
||||
import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.import.Run", ProcessRun) // deprecated → yao.import.Run
|
||||
gou.RegisterProcessHandler("xiang.import.Data", ProcessData) // deprecated → yao.import.Data
|
||||
gou.RegisterProcessHandler("xiang.import.Setting", ProcessSetting) // deprecated → yao.import.Setting
|
||||
gou.RegisterProcessHandler("xiang.import.DataSetting", ProcessDataSetting) // deprecated → yao.import.DataSetting
|
||||
gou.RegisterProcessHandler("xiang.import.Mapping", ProcessMapping) // deprecated → yao.import.Mapping
|
||||
gou.RegisterProcessHandler("xiang.import.MappingSetting", ProcessMappingSetting) // deprecated → yao.import.MappingSetting
|
||||
process.Register("xiang.import.Run", ProcessRun) // deprecated → yao.import.Run
|
||||
process.Register("xiang.import.Data", ProcessData) // deprecated → yao.import.Data
|
||||
process.Register("xiang.import.Setting", ProcessSetting) // deprecated → yao.import.Setting
|
||||
process.Register("xiang.import.DataSetting", ProcessDataSetting) // deprecated → yao.import.DataSetting
|
||||
process.Register("xiang.import.Mapping", ProcessMapping) // deprecated → yao.import.Mapping
|
||||
process.Register("xiang.import.MappingSetting", ProcessMappingSetting) // deprecated → yao.import.MappingSetting
|
||||
|
||||
gou.AliasProcess("xiang.import.Run", "yao.import.Run")
|
||||
gou.AliasProcess("xiang.import.Data", "yao.import.Data")
|
||||
gou.AliasProcess("xiang.import.Setting", "yao.import.Setting")
|
||||
gou.AliasProcess("xiang.import.DataSetting", "yao.import.DataSetting")
|
||||
gou.AliasProcess("xiang.import.Mapping", "yao.import.Mapping")
|
||||
gou.AliasProcess("xiang.import.MappingSetting", "yao.import.MappingSetting")
|
||||
process.Alias("xiang.import.Run", "yao.import.Run")
|
||||
process.Alias("xiang.import.Data", "yao.import.Data")
|
||||
process.Alias("xiang.import.Setting", "yao.import.Setting")
|
||||
process.Alias("xiang.import.DataSetting", "yao.import.DataSetting")
|
||||
process.Alias("xiang.import.Mapping", "yao.import.Mapping")
|
||||
process.Alias("xiang.import.MappingSetting", "yao.import.MappingSetting")
|
||||
}
|
||||
|
||||
// ProcessRun xiang.import.Run
|
||||
// 导入数据
|
||||
func ProcessRun(process *gou.Process) interface{} {
|
||||
func ProcessRun(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(3)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
@ -39,7 +39,7 @@ func ProcessRun(process *gou.Process) interface{} {
|
|||
|
||||
// ProcessSetting xiang.import.Setting
|
||||
// 导入配置选项
|
||||
func ProcessSetting(process *gou.Process) interface{} {
|
||||
func ProcessSetting(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
@ -53,7 +53,7 @@ func ProcessSetting(process *gou.Process) interface{} {
|
|||
|
||||
// ProcessData xiang.import.Data
|
||||
// 数据预览
|
||||
func ProcessData(process *gou.Process) interface{} {
|
||||
func ProcessData(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(5)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
@ -71,7 +71,7 @@ func ProcessData(process *gou.Process) interface{} {
|
|||
|
||||
// ProcessDataSetting xiang.import.DataSetting
|
||||
// 数据预览表格配置
|
||||
func ProcessDataSetting(process *gou.Process) interface{} {
|
||||
func ProcessDataSetting(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
@ -80,7 +80,7 @@ func ProcessDataSetting(process *gou.Process) interface{} {
|
|||
|
||||
// ProcessMapping xiang.import.Mapping
|
||||
// 字段映射预览
|
||||
func ProcessMapping(process *gou.Process) interface{} {
|
||||
func ProcessMapping(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
@ -93,7 +93,7 @@ func ProcessMapping(process *gou.Process) interface{} {
|
|||
|
||||
// ProcessMappingSetting xiang.import.MappingSetting
|
||||
// 字段映射表格配置
|
||||
func ProcessMappingSetting(process *gou.Process) interface{} {
|
||||
func ProcessMappingSetting(process *process.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
imp := Select(name).WithSid(process.Sid)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/process"
|
||||
)
|
||||
|
||||
func TestProcessMapping(t *testing.T) {
|
||||
simple := filepath.Join("assets", "simple.xlsx")
|
||||
args := []interface{}{"order", simple}
|
||||
response := gou.NewProcess("xiang.import.Mapping", args...).Run()
|
||||
response := process.New("xiang.import.Mapping", args...).Run()
|
||||
_, ok := response.(*Mapping)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
|
@ -19,39 +19,39 @@ func TestProcessMapping(t *testing.T) {
|
|||
func TestProcessMappingSetting(t *testing.T) {
|
||||
simple := filepath.Join("assets", "simple.xlsx")
|
||||
args := []interface{}{"order", simple}
|
||||
response := gou.NewProcess("xiang.import.MappingSetting", args...).Run()
|
||||
response := process.New("xiang.import.MappingSetting", args...).Run()
|
||||
_, ok := response.(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestProcessData(t *testing.T) {
|
||||
simple := filepath.Join("assets", "simple.xlsx")
|
||||
mapping := gou.NewProcess("xiang.import.Mapping", "order", simple).Run()
|
||||
mapping := process.New("xiang.import.Mapping", "order", simple).Run()
|
||||
args := []interface{}{"order", simple, 1, 2, mapping}
|
||||
response := gou.NewProcess("xiang.import.Data", args...).Run()
|
||||
response := process.New("xiang.import.Data", args...).Run()
|
||||
_, ok := response.(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestProcessDataSetting(t *testing.T) {
|
||||
args := []interface{}{"order"}
|
||||
response := gou.NewProcess("xiang.import.DataSetting", args...).Run()
|
||||
response := process.New("xiang.import.DataSetting", args...).Run()
|
||||
_, ok := response.(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestProcessSetting(t *testing.T) {
|
||||
args := []interface{}{"order"}
|
||||
response := gou.NewProcess("xiang.import.Setting", args...).Run()
|
||||
response := process.New("xiang.import.Setting", args...).Run()
|
||||
_, ok := response.(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestProcessRun(t *testing.T) {
|
||||
simple := filepath.Join("assets", "simple.xlsx")
|
||||
mapping := gou.NewProcess("xiang.import.Mapping", "order", simple).Run()
|
||||
mapping := process.New("xiang.import.Mapping", "order", simple).Run()
|
||||
args := []interface{}{"order", simple, mapping}
|
||||
response := gou.NewProcess("xiang.import.Run", args...).Run()
|
||||
response := process.New("xiang.import.Run", args...).Run()
|
||||
_, ok := response.(map[string]int)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ func TestMain(m *testing.M) {
|
|||
exitVal := m.Run()
|
||||
|
||||
// we can do clean up code here
|
||||
gou.KillPlugins()
|
||||
plugin.KillAll()
|
||||
|
||||
os.Exit(exitVal)
|
||||
}
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -6,11 +6,8 @@ import (
|
|||
_ "github.com/yaoapp/gou/encoding"
|
||||
_ "github.com/yaoapp/yao/crypto"
|
||||
_ "github.com/yaoapp/yao/helper"
|
||||
_ "github.com/yaoapp/yao/network"
|
||||
_ "github.com/yaoapp/yao/system"
|
||||
_ "github.com/yaoapp/yao/user"
|
||||
_ "github.com/yaoapp/yao/utils"
|
||||
_ "github.com/yaoapp/yao/xfs"
|
||||
)
|
||||
|
||||
// 主程序
|
||||
|
|
|
|||
|
|
@ -1,54 +1,17 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load 加载数据模型
|
||||
func Load(cfg config.Config) error {
|
||||
if share.BUILDIN {
|
||||
return LoadBuildIn("models", "")
|
||||
}
|
||||
return LoadFrom(filepath.Join(cfg.Root, "models"), "")
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
messages := []string{}
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := gou.LoadModelReturn(string(content), name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
messages = append(messages, err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
messages = append(messages, err.Error())
|
||||
}
|
||||
|
||||
if len(messages) > 0 {
|
||||
return fmt.Errorf("[Model] %s", strings.Join(messages, ";"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadBuildIn 从制品中读取
|
||||
func LoadBuildIn(dir string, prefix string) error {
|
||||
return nil
|
||||
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
_, err := model.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,27 +5,25 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
share.DBConnect(config.Conf.DB)
|
||||
gou.Models = make(map[string]*gou.Model)
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range gou.Models {
|
||||
for key := range model.Models {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 11, len(keys))
|
||||
|
||||
demo := gou.Select("demo")
|
||||
demo := model.Select("demo")
|
||||
assert.Equal(t, demo.MetaData.Name, "::Demo")
|
||||
assert.Equal(t, demo.Columns["action"].Label, "::Action")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
)
|
||||
|
||||
// IP 读取IP地址
|
||||
func IP() map[string]string {
|
||||
res := map[string]string{}
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
exception.New("读取网卡失败 %s", 500, err.Error()).Throw()
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
addrs, err := i.Addrs()
|
||||
if err != nil {
|
||||
exception.New("读取IP地址失败 %s", 500, err.Error()).Throw()
|
||||
}
|
||||
// handle err
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
res[i.Name] = ip.String()
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ProcessIP xiang.network.IP IP地址
|
||||
func ProcessIP(process *gou.Process) interface{} {
|
||||
return IP()
|
||||
}
|
||||
|
||||
// FreePort xiang.network.FreePort 获取可用端口
|
||||
func FreePort() int {
|
||||
addr, err := net.ResolveTCPAddr("tcp", ":0")
|
||||
if err != nil {
|
||||
exception.New("获取可用端口失败 %s", 500, err.Error()).Throw()
|
||||
return 0
|
||||
}
|
||||
|
||||
l, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
exception.New("获取可用端口失败 %s", 500, err.Error()).Throw()
|
||||
return 0
|
||||
}
|
||||
|
||||
defer l.Close()
|
||||
return l.Addr().(*net.TCPAddr).Port
|
||||
}
|
||||
|
||||
// ProcessFreePort xiang.network.FreePort 获取可用端口
|
||||
func ProcessFreePort(process *gou.Process) interface{} {
|
||||
return FreePort()
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
)
|
||||
|
||||
func TestIP(t *testing.T) {
|
||||
resp := IP()
|
||||
assert.True(t, len(resp) > 0)
|
||||
}
|
||||
|
||||
func TestProcessIP(t *testing.T) {
|
||||
res := gou.NewProcess("xiang.network.ip").Run()
|
||||
resp, ok := res.(map[string]string)
|
||||
assert.True(t, ok)
|
||||
assert.True(t, len(resp) > 0)
|
||||
}
|
||||
|
||||
func TestFreePort(t *testing.T) {
|
||||
port := FreePort()
|
||||
assert.True(t, port > 0)
|
||||
}
|
||||
|
||||
func TestProcessFreePort(t *testing.T) {
|
||||
res := gou.NewProcess("xiang.network.FreePort").Run()
|
||||
port, ok := res.(int)
|
||||
assert.True(t, ok)
|
||||
assert.True(t, port > 0)
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package network
|
||||
|
||||
// *******************************************************
|
||||
// * DEPRECATED → http *
|
||||
// *******************************************************
|
||||
|
||||
import "github.com/yaoapp/gou"
|
||||
|
||||
func init() {
|
||||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.network.ip", ProcessIP)
|
||||
gou.RegisterProcessHandler("xiang.network.FreePort", ProcessFreePort)
|
||||
gou.RegisterProcessHandler("xiang.network.Get", ProcessGet)
|
||||
gou.RegisterProcessHandler("xiang.network.Post", ProcessPost)
|
||||
gou.RegisterProcessHandler("xiang.network.PostJSON", ProcessPostJSON)
|
||||
gou.RegisterProcessHandler("xiang.network.Put", ProcessPut)
|
||||
gou.RegisterProcessHandler("xiang.network.PutJSON", ProcessPutJSON)
|
||||
gou.RegisterProcessHandler("xiang.network.Send", ProcessSend)
|
||||
}
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
package network
|
||||
|
||||
// *******************************************************
|
||||
// * DEPRECATED → http *
|
||||
// *******************************************************
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou/dns"
|
||||
)
|
||||
|
||||
// Response 请求响应结果
|
||||
type Response struct {
|
||||
Status int `json:"status"`
|
||||
Body string `json:"body"`
|
||||
Data interface{} `json:"data"`
|
||||
Headers map[string]interface{} `json:"headers"`
|
||||
}
|
||||
|
||||
// RequestGet 发送GET请求
|
||||
func RequestGet(url string, params map[string]interface{}, headers map[string]string) Response {
|
||||
return RequestSend("GET", url, params, nil, headers)
|
||||
}
|
||||
|
||||
// RequestPost 发送POST请求
|
||||
func RequestPost(url string, data interface{}, headers map[string]string) Response {
|
||||
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestPostJSON 发送POST请求
|
||||
func RequestPostJSON(url string, data interface{}, headers map[string]string) Response {
|
||||
if headers == nil {
|
||||
headers = map[string]string{}
|
||||
}
|
||||
headers["content-type"] = "application/json;charset=utf8"
|
||||
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestPut 发送PUT请求
|
||||
func RequestPut(url string, data interface{}, headers map[string]string) Response {
|
||||
return RequestSend("PUT", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestPutJSON 发送PUT请求
|
||||
func RequestPutJSON(url string, data interface{}, headers map[string]string) Response {
|
||||
if headers == nil {
|
||||
headers = map[string]string{}
|
||||
}
|
||||
headers["content-type"] = "application/json;charset=utf8"
|
||||
return RequestSend("PUT", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestSend 发送Request请求
|
||||
func RequestSend(method string, url string, params map[string]interface{}, data interface{}, headers map[string]string) Response {
|
||||
|
||||
var body []byte
|
||||
var err error
|
||||
if data != nil {
|
||||
if strings.HasPrefix(strings.ToLower(headers["content-type"]), "application/json") {
|
||||
body, err = jsoniter.Marshal(data)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": 500, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
body = []byte(fmt.Sprintf("%v", data))
|
||||
}
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": 500, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Request Header
|
||||
if headers != nil {
|
||||
for name, header := range headers {
|
||||
req.Header.Set(name, header)
|
||||
}
|
||||
}
|
||||
|
||||
// Force using system DSN resolver
|
||||
// var dialer = &net.Dialer{Resolver: &net.Resolver{PreferGo: false}}
|
||||
var dialContext = dns.DialContext()
|
||||
var tr = &http.Transport{DialContext: dialContext}
|
||||
var client *http.Client = &http.Client{Transport: tr}
|
||||
|
||||
// Https SkipVerify false
|
||||
if strings.HasPrefix(url, "https://") {
|
||||
tr = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
DialContext: dialContext,
|
||||
}
|
||||
client = &http.Client{Transport: tr}
|
||||
}
|
||||
defer tr.CloseIdleConnections()
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 0,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": 500, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err = ioutil.ReadAll(resp.Body) // response body is []byte
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": resp.StatusCode, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// JSON 解析
|
||||
var res interface{}
|
||||
if strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
|
||||
err = jsoniter.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": resp.StatusCode, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
respHeaders := map[string]interface{}{}
|
||||
for name := range resp.Header {
|
||||
respHeaders[name] = resp.Header.Get(name)
|
||||
}
|
||||
return Response{
|
||||
Status: resp.StatusCode,
|
||||
Body: string(body),
|
||||
Data: res,
|
||||
Headers: respHeaders,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
)
|
||||
|
||||
// *******************************************************
|
||||
// * DEPRECATED → http *
|
||||
// *******************************************************
|
||||
|
||||
// ProcessPost xiang.helper.Post HTTP Post
|
||||
func ProcessPost(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var data interface{}
|
||||
var headers = map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
data = process.Args[1]
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestPost(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessPostJSON xiang.helper.PostJSON HTTP Post
|
||||
func ProcessPostJSON(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var data interface{}
|
||||
var headers = map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
data = process.Args[1]
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestPostJSON(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessPut xiang.helper.Put HTTP PUT
|
||||
func ProcessPut(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var data interface{}
|
||||
var headers = map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
data = process.Args[1]
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestPut(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessPutJSON xiang.helper.PutJSON HTTP PUT
|
||||
func ProcessPutJSON(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var data interface{}
|
||||
var headers = map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
data = process.Args[1]
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestPutJSON(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessSend xiang.helper.Send HTTP Send
|
||||
func ProcessSend(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
var data interface{}
|
||||
var params = map[string]interface{}{}
|
||||
var headers = map[string]string{}
|
||||
method := process.ArgsString(0)
|
||||
url := process.ArgsString(1)
|
||||
if process.NumOfArgs() > 2 {
|
||||
params = process.ArgsMap(2)
|
||||
}
|
||||
|
||||
if process.NumOfArgs() > 3 {
|
||||
data = process.Args[3]
|
||||
}
|
||||
|
||||
if process.NumOfArgs() > 4 {
|
||||
inputHeaders := process.ArgsMap(4)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestSend(method, url, params, data, headers)
|
||||
}
|
||||
|
||||
// ProcessGet xiang.helper.Get HTTP Get
|
||||
func ProcessGet(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var params = map[string]interface{}{}
|
||||
var headers = map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
params = process.ArgsMap(1)
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
|
||||
return RequestGet(url, params, headers)
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/any"
|
||||
)
|
||||
|
||||
func TestRequestGetHtml(t *testing.T) {
|
||||
resp := RequestGet("https://api.github.com/zen", nil, nil)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
assert.Equal(t, nil, resp.Data)
|
||||
}
|
||||
|
||||
func TestRequestGetJSON(t *testing.T) {
|
||||
resp := RequestGet("https://api.github.com/users/yaoapp", nil, nil)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
data := any.Of(resp.Data).MapStr().Dot()
|
||||
assert.Equal(t, "https://github.com/YaoApp", data.Get("html_url"))
|
||||
}
|
||||
|
||||
func TestRequestPost(t *testing.T) {
|
||||
resp := RequestPost("https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestPostJSON(t *testing.T) {
|
||||
resp := RequestPostJSON("https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestProcessGet(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen"}
|
||||
res := gou.NewProcess("xiang.network.Get", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
assert.Equal(t, nil, resp.Data)
|
||||
}
|
||||
|
||||
func TestRequestProcessPost(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil}
|
||||
res := gou.NewProcess("xiang.network.Post", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestProcessPostJSON(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil}
|
||||
res := gou.NewProcess("xiang.network.PostJSON", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestProcessSend(t *testing.T) {
|
||||
args := []interface{}{"GET", "https://api.github.com/zen"}
|
||||
res := gou.NewProcess("xiang.network.Send", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
assert.Equal(t, nil, resp.Data)
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
# 数据页面
|
||||
60
page/api.go
60
page/api.go
|
|
@ -1,60 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// SetupAPIs 设定API数据
|
||||
func (page *Page) SetupAPIs() {
|
||||
|
||||
defaults := map[string]share.API{
|
||||
"data": apiDataDefault(),
|
||||
"setting": apiSettingDefault(),
|
||||
}
|
||||
|
||||
// 开发者填写的规则
|
||||
for name := range page.APIs {
|
||||
if _, has := defaults[name]; !has {
|
||||
delete(page.APIs, name)
|
||||
continue
|
||||
}
|
||||
|
||||
api := defaults[name]
|
||||
api.Name = name
|
||||
if page.APIs[name].Process != "" {
|
||||
api.Process = page.APIs[name].Process
|
||||
}
|
||||
|
||||
if page.APIs[name].Guard != "" {
|
||||
api.Guard = page.APIs[name].Guard
|
||||
}
|
||||
|
||||
if page.APIs[name].Default != nil {
|
||||
api.Default = page.APIs[name].Default
|
||||
}
|
||||
|
||||
defaults[name] = api
|
||||
}
|
||||
|
||||
page.APIs = defaults
|
||||
}
|
||||
|
||||
// apiSearchDefault data 接口默认值
|
||||
func apiDataDefault() share.API {
|
||||
param := map[string]interface{}{}
|
||||
return share.API{
|
||||
Name: "data",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "xiang.page.data",
|
||||
Default: []interface{}{param},
|
||||
}
|
||||
}
|
||||
|
||||
// apiSettingDefault setting 接口默认值
|
||||
func apiSettingDefault() share.API {
|
||||
return share.API{
|
||||
Name: "setting",
|
||||
Guard: "bearer-jwt",
|
||||
Process: "xiang.page.setting",
|
||||
}
|
||||
}
|
||||
125
page/lang.go
125
page/lang.go
|
|
@ -1,125 +0,0 @@
|
|||
package page
|
||||
|
||||
// Lang for applying a language pack
|
||||
func (page *Page) Lang(trans func(widget string, inst string, value *string) bool) {
|
||||
inst := page.Flow.Name
|
||||
widget := "page"
|
||||
|
||||
trans(widget, inst, &page.Name)
|
||||
trans(widget, inst, &page.Label)
|
||||
trans(widget, inst, &page.Description)
|
||||
trans(widget, inst, &page.Page.Primary)
|
||||
transMap(widget, inst, page.Page.Layout, trans)
|
||||
page.Output = transAny(widget, inst, page.Output, trans)
|
||||
|
||||
// Filters
|
||||
for name, filter := range page.Filters {
|
||||
new := name
|
||||
trans(widget, inst, &new)
|
||||
trans(widget, inst, &filter.Label)
|
||||
delete(page.Filters, name)
|
||||
|
||||
// Props
|
||||
transMap(widget, inst, filter.Input.Props, trans)
|
||||
page.Filters[new] = filter
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func transAny(widget string, inst string, input interface{}, trans func(widget string, inst string, value *string) bool) interface{} {
|
||||
switch input.(type) {
|
||||
case []interface{}:
|
||||
values := input.([]interface{})
|
||||
transArr(widget, inst, values, trans)
|
||||
input = values
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
values := input.(map[string]interface{})
|
||||
for name, value := range values {
|
||||
new := name
|
||||
newValue := value
|
||||
|
||||
switch value.(type) {
|
||||
case string:
|
||||
val := value.(string)
|
||||
trans(widget, inst, &val)
|
||||
newValue = val
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
vals := value.([]interface{})
|
||||
transArr(widget, inst, vals, trans)
|
||||
newValue = vals
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
vals := value.(map[string]interface{})
|
||||
transMap(widget, inst, vals, trans)
|
||||
newValue = vals
|
||||
break
|
||||
}
|
||||
|
||||
trans(widget, inst, &new)
|
||||
delete(values, name)
|
||||
values[new] = newValue
|
||||
}
|
||||
input = values
|
||||
break
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
func transMap(widget string, inst string, values map[string]interface{}, trans func(widget string, inst string, value *string) bool) {
|
||||
for key, value := range values {
|
||||
|
||||
switch value.(type) {
|
||||
|
||||
case string:
|
||||
v := value.(string)
|
||||
trans(widget, inst, &v)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
v := value.([]interface{})
|
||||
transArr(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
v := value.(map[string]interface{})
|
||||
transMap(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func transArr(widget string, inst string, values []interface{}, trans func(widget string, inst string, value *string) bool) {
|
||||
for key, value := range values {
|
||||
switch value.(type) {
|
||||
|
||||
case string:
|
||||
v := value.(string)
|
||||
trans(widget, inst, &v)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case []interface{}:
|
||||
v := value.([]interface{})
|
||||
transArr(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
|
||||
case map[string]interface{}:
|
||||
v := value.(map[string]interface{})
|
||||
transMap(widget, inst, v, trans)
|
||||
values[key] = v
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
121
page/page.go
121
page/page.go
|
|
@ -1,121 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/lang"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Pages 已载入页面
|
||||
var Pages = map[string]*Page{}
|
||||
|
||||
// Load 加载页面
|
||||
func Load(cfg config.Config) error {
|
||||
|
||||
if share.BUILDIN {
|
||||
return LoadBuildIn("pages", "")
|
||||
}
|
||||
|
||||
var errs error = nil
|
||||
if err := LoadFrom(path.Join(cfg.Root, "/kanban"), ""); err != nil {
|
||||
// log.Trace("load kanban error: %s ", err.Error())
|
||||
errs = err
|
||||
}
|
||||
if err := LoadFrom(path.Join(cfg.Root, "/screen"), ""); err != nil {
|
||||
// log.Trace("load screen error: %s", err.Error())
|
||||
errs = err
|
||||
}
|
||||
if err := LoadFrom(path.Join(cfg.Root, "/pages"), ""); err != nil {
|
||||
// log.Trace("load screen error: %s", err.Error())
|
||||
errs = err
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
// LoadBuildIn 从制品中读取
|
||||
func LoadBuildIn(dir string, prefix string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string, prefix string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".json", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
content := share.ReadFile(filename)
|
||||
_, err := LoadPage(content, name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Load Script
|
||||
err = share.Walk(dir, ".js", func(root, filename string) {
|
||||
name := prefix + share.SpecName(root, filename)
|
||||
page := Select(name)
|
||||
if page != nil {
|
||||
script := share.ScriptName(filename)
|
||||
content := share.ReadFile(filename)
|
||||
page.LoadScript(string(content), script)
|
||||
}
|
||||
})
|
||||
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
// LoadPage 载入页面
|
||||
func LoadPage(source []byte, name string) (*Page, error) {
|
||||
page := &Page{
|
||||
Flow: gou.Flow{
|
||||
Name: name,
|
||||
},
|
||||
}
|
||||
err := jsoniter.Unmarshal(source, page)
|
||||
if err != nil {
|
||||
log.With(log.F{"name": name, "source": source}).Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
page.Prepare()
|
||||
page.SetupAPIs()
|
||||
Pages[name] = page
|
||||
|
||||
// Apply a language pack
|
||||
if lang.Default != nil {
|
||||
lang.Default.Apply(Pages[name])
|
||||
}
|
||||
|
||||
return page, nil
|
||||
}
|
||||
|
||||
// Select 读取已加载页面
|
||||
func Select(name string) *Page {
|
||||
page, has := Pages[name]
|
||||
if !has {
|
||||
exception.New(
|
||||
fmt.Sprintf("Page:%s; 尚未加载", name),
|
||||
400,
|
||||
).Throw()
|
||||
}
|
||||
return page
|
||||
}
|
||||
|
||||
// GetData 运行 flow 返回数值
|
||||
func (page Page) GetData(params map[string]interface{}) interface{} {
|
||||
return page.Flow.Exec(params)
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
|
||||
share.DBConnect(config.Conf.DB)
|
||||
model.Load(config.Conf)
|
||||
query.Load(config.Conf)
|
||||
|
||||
Load(config.Conf)
|
||||
LoadFrom("not a path", "404.")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range Pages {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 2, len(keys))
|
||||
_, err := i18n.Trans("zh-hk", []string{"chart.lang"}, Pages["lang"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// lang := Pages["lang"]
|
||||
// output := lang.Output.(map[string]interface{})
|
||||
// assert.Equal(t, "{{$in}}", output["參數"])
|
||||
|
||||
// filters := lang.Page.Layout["filters"].([]interface{})
|
||||
// begin := filters[0].(map[string]interface{})
|
||||
// assert.Equal(t, "開始時間", begin["name"])
|
||||
|
||||
// assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
)
|
||||
|
||||
// 注册处理器
|
||||
func init() {
|
||||
gou.RegisterProcessHandler("xiang.page.data", ProcessData)
|
||||
gou.RegisterProcessHandler("xiang.page.setting", ProcessSetting)
|
||||
}
|
||||
|
||||
// ProcessData xiang.page.data
|
||||
// 查询数据分析页面中定义的数据
|
||||
func ProcessData(process *gou.Process) interface{} {
|
||||
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
params := process.ArgsMap(1)
|
||||
page := Select(name)
|
||||
api := page.APIs["data"]
|
||||
|
||||
if len(api.Default) > 0 {
|
||||
if defaults, ok := api.Default[0].(map[string]interface{}); ok {
|
||||
for key, value := range defaults {
|
||||
if !params.Has(key) {
|
||||
params.Set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// with Session
|
||||
page.Flow.WithGlobal(process.Global)
|
||||
page.Flow.WithSID(process.Sid)
|
||||
|
||||
return page.GetData(params)
|
||||
}
|
||||
|
||||
// ProcessSetting xiang.page.setting
|
||||
// 查询数据分析页面中定义的数据
|
||||
func ProcessSetting(process *gou.Process) interface{} {
|
||||
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
field := process.ArgsString(1)
|
||||
page := Select(name)
|
||||
|
||||
fields := strings.Split(field, ",")
|
||||
setting := maps.Map{
|
||||
"name": page.Name,
|
||||
"label": page.Label,
|
||||
"version": page.Version,
|
||||
"description": page.Description,
|
||||
"filters": page.Filters,
|
||||
"page": page.Page,
|
||||
}
|
||||
|
||||
if len(fields) == 1 && setting.Has(fields[0]) {
|
||||
field := strings.TrimSpace(fields[0])
|
||||
return setting.Get(field)
|
||||
}
|
||||
|
||||
if len(fields) > 1 {
|
||||
res := maps.Map{}
|
||||
for _, field := range fields {
|
||||
field = strings.TrimSpace(field)
|
||||
if setting.Has(field) {
|
||||
res.Set(field, setting.Get(field))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
return setting
|
||||
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/yao/config"
|
||||
_ "github.com/yaoapp/yao/helper"
|
||||
"github.com/yaoapp/yao/model"
|
||||
"github.com/yaoapp/yao/query"
|
||||
"github.com/yaoapp/yao/runtime"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
func init() {
|
||||
runtime.Load(config.Conf)
|
||||
share.DBConnect(config.Conf.DB)
|
||||
model.Load(config.Conf)
|
||||
query.Load(config.Conf)
|
||||
Load(config.Conf)
|
||||
}
|
||||
func TestProcessSetting(t *testing.T) {
|
||||
|
||||
args := []interface{}{
|
||||
"service.compare",
|
||||
nil,
|
||||
&gin.Context{},
|
||||
}
|
||||
process := gou.NewProcess("xiang.page.Setting", args...)
|
||||
response := ProcessSetting(process)
|
||||
assert.NotNil(t, response)
|
||||
res := any.Of(response).Map()
|
||||
assert.True(t, res.Has("name"))
|
||||
assert.True(t, res.Has("label"))
|
||||
assert.True(t, res.Has("description"))
|
||||
assert.True(t, res.Has("page"))
|
||||
assert.True(t, res.Has("version"))
|
||||
|
||||
args = []interface{}{
|
||||
"service.compare",
|
||||
"page,name",
|
||||
&gin.Context{},
|
||||
}
|
||||
process = gou.NewProcess("xiang.page.Setting", args...)
|
||||
response = ProcessSetting(process)
|
||||
assert.NotNil(t, response)
|
||||
|
||||
res = any.Of(response).Map()
|
||||
assert.True(t, res.Has("name"))
|
||||
assert.True(t, res.Has("page"))
|
||||
assert.False(t, res.Has("label"))
|
||||
}
|
||||
|
||||
func TestProcessData(t *testing.T) {
|
||||
|
||||
params := url.Values{
|
||||
"from": []string{"1981-01-01", "1990-01-01"},
|
||||
}
|
||||
params.Set("to", "2049-12-31")
|
||||
|
||||
args := []interface{}{
|
||||
"service.compare",
|
||||
params,
|
||||
&gin.Context{},
|
||||
}
|
||||
process := gou.NewProcess("xiang.page.Data", args...)
|
||||
response := ProcessData(process)
|
||||
assert.NotNil(t, response)
|
||||
|
||||
res := any.Of(response).Map().Dot()
|
||||
assert.Equal(t, "北京", res.Get("合并.0.城市"))
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Page 页面格式
|
||||
type Page struct {
|
||||
gou.Flow
|
||||
APIs map[string]share.API `json:"apis,omitempty"`
|
||||
Filters map[string]share.Filter `json:"filters,omitempty"`
|
||||
Page share.Page `json:"page,omitempty"`
|
||||
}
|
||||
|
|
@ -1,33 +1,17 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Load 加载业务插件
|
||||
func Load(cfg config.Config) error {
|
||||
return LoadFrom(filepath.Join(cfg.Root, "plugins"))
|
||||
}
|
||||
|
||||
// LoadFrom 从特定目录加载
|
||||
func LoadFrom(dir string) error {
|
||||
|
||||
if share.DirNotExists(dir) {
|
||||
return fmt.Errorf("%s does not exists", dir)
|
||||
}
|
||||
|
||||
err := share.Walk(dir, ".so", func(root, filename string) {
|
||||
name := share.SpecName(root, filename)
|
||||
_, err := gou.LoadPluginReturn(filename, name)
|
||||
if err != nil {
|
||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||
}
|
||||
})
|
||||
return err
|
||||
exts := []string{"*.so"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
_, err := plugin.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,20 +5,18 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/plugin"
|
||||
"github.com/yaoapp/yao/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
gou.Plugins = make(map[string]*gou.Plugin)
|
||||
Load(config.Conf)
|
||||
LoadFrom("404")
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range gou.Plugins {
|
||||
for key := range plugin.Plugins {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 1, len(keys))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/gou/query"
|
||||
dsl "github.com/yaoapp/gou/query/gou"
|
||||
"github.com/yaoapp/kun/log"
|
||||
|
|
@ -19,7 +19,7 @@ func DefaultQuery() {
|
|||
query.Register("default", &dsl.Query{
|
||||
Query: capsule.Query(),
|
||||
GetTableName: func(s string) string {
|
||||
if mod, has := gou.Models[s]; has {
|
||||
if mod, has := model.Models[s]; has {
|
||||
return mod.MetaData.Table.Name
|
||||
}
|
||||
log.Error("%s model does not load", s)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue