mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
iot init
This commit is contained in:
@@ -12,7 +12,6 @@ type ScriptEngine interface {
|
||||
ScriptOnSwitch() ([]string, error)
|
||||
ScriptOnFilter() (bool, error)
|
||||
ScriptToString() (string, error)
|
||||
ScriptAlarmDetails() (map[string]interface{}, error)
|
||||
ScriptGenerate() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
@@ -105,24 +104,6 @@ func (bse *baseScriptEngine) ScriptToString() (string, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (bse *baseScriptEngine) ScriptAlarmDetails() (map[string]interface{}, error) {
|
||||
msg := bse.Msg
|
||||
vm := goja.New()
|
||||
_, err := vm.RunString(bse.Script)
|
||||
if err != nil {
|
||||
logrus.Info("JS代码有问题")
|
||||
return nil, err
|
||||
}
|
||||
var fn func(map[string]interface{}, map[string]interface{}, string) map[string]interface{}
|
||||
err = vm.ExportTo(vm.Get(bse.Fun), &fn)
|
||||
if err != nil {
|
||||
logrus.Info("Js函数映射到 Go 函数失败!")
|
||||
return nil, err
|
||||
}
|
||||
datas := fn(msg.GetMsg(), msg.GetMetadata().GetValues(), msg.GetType())
|
||||
return datas, nil
|
||||
}
|
||||
|
||||
func (bse *baseScriptEngine) ScriptGenerate() (map[string]interface{}, error) {
|
||||
msg := bse.Msg
|
||||
vm := goja.New()
|
||||
|
||||
Reference in New Issue
Block a user