-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathexec.go
53 lines (43 loc) · 1.23 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package flow
import (
"context"
"encoding/json"
"github.com/antlinker/flow/expression"
)
// Execer 表达式执行器
type Execer interface {
// 执行表达式返回布尔类型的值
ExecReturnBool(ctx context.Context, exp, params []byte) (bool, error)
// 执行表达式返回字符串切片类型的值
ExecReturnStringSlice(ctx context.Context, exp, params []byte) ([]string, error)
}
// NewQLangExecer 创建基于qlang的表达式执行器
func NewQLangExecer() Execer {
return &execer{}
}
type execer struct {
}
func (*execer) ExecReturnBool(ctx context.Context, exp, params []byte) (bool, error) {
var m map[string]interface{}
err := json.Unmarshal(params, &m)
if err != nil {
return false, err
}
expCtx, ok := FromExpContext(ctx)
if ok {
return expression.ExecParamBool(expCtx, string(exp), m)
}
return expression.ExecParamBool(ctx, string(exp), m)
}
func (*execer) ExecReturnStringSlice(ctx context.Context, exp, params []byte) ([]string, error) {
var m map[string]interface{}
err := json.Unmarshal(params, &m)
if err != nil {
return nil, err
}
expCtx, ok := FromExpContext(ctx)
if ok {
return expression.ExecParamSliceStr(expCtx, string(exp), m)
}
return expression.ExecParamSliceStr(ctx, string(exp), m)
}