更新引擎
This commit is contained in:
parent
856c720eaf
commit
30069763a8
5 changed files with 13 additions and 8 deletions
1
go.mod
1
go.mod
|
|
@ -47,6 +47,7 @@ require (
|
|||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
||||
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect
|
||||
google.golang.org/grpc v1.42.0 // indirect
|
||||
rogchap.com/v8go v0.7.0 // indirect
|
||||
)
|
||||
|
||||
// go env -w GOPRIVATE=github.com/yaoapp/*
|
||||
|
|
|
|||
1
go.sum
1
go.sum
|
|
@ -886,6 +886,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
rogchap.com/v8go v0.7.0 h1:kgjbiO4zE5itA962ze6Hqmbs4HgZbGzmueCXsZtremg=
|
||||
rogchap.com/v8go v0.7.0/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
|
|
|
|||
|
|
@ -143,8 +143,11 @@ func (imp *Importer) DataClean(data [][]interface{}, bindings []*Binding) ([]str
|
|||
success := true
|
||||
for i, binding := range bindings { // 调用字段清洗处理器
|
||||
for _, rule := range binding.Rules {
|
||||
if !DataValidate(row, row[i], rule) {
|
||||
update, ok := DataValidate(row, row[i], rule)
|
||||
if !ok {
|
||||
success = false
|
||||
} else {
|
||||
row = update
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -157,23 +160,23 @@ func (imp *Importer) DataClean(data [][]interface{}, bindings []*Binding) ([]str
|
|||
}
|
||||
|
||||
// DataValidate 数值校验
|
||||
func DataValidate(row []interface{}, value interface{}, rule string) bool {
|
||||
func DataValidate(row []interface{}, value interface{}, rule string) ([]interface{}, bool) {
|
||||
process, err := gou.ProcessOf(rule, value, row)
|
||||
if err != nil {
|
||||
xlog.Printf("DataValidate: %s %s", rule, err.Error())
|
||||
return true
|
||||
return row, true
|
||||
}
|
||||
res, err := process.Exec()
|
||||
if err != nil {
|
||||
xlog.Printf("DataValidate: %s %s", rule, err.Error())
|
||||
return true
|
||||
return row, true
|
||||
}
|
||||
|
||||
if update, ok := res.([]interface{}); ok {
|
||||
row = update
|
||||
return true
|
||||
return update, true
|
||||
}
|
||||
return false
|
||||
return row, false
|
||||
}
|
||||
|
||||
// DataPreview 预览数据
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func LoadFrom(dir string) {
|
|||
// 加载共享脚本
|
||||
Walk(dir, ".js", func(root, filename string) {
|
||||
name := SpecName(root, filename)
|
||||
err := gou.JavaScriptVM.Load(filename, name)
|
||||
err := gou.Yao.Load(filename, name)
|
||||
if err != nil {
|
||||
xlog.Printf("加载脚本失败 %s", err.Error())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func TestAPI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestScript(t *testing.T) {
|
||||
res, err := gou.JavaScriptVM.Run("time", "hello", "world")
|
||||
res, err := gou.Yao.New("time", "hello").Call("world")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "name:world", res)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue