-
Notifications
You must be signed in to change notification settings - Fork 327
/
corredor_handler.gen.go
117 lines (98 loc) · 2.32 KB
/
corredor_handler.gen.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package automation
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// automation/automation/corredor_handler.yaml
import (
"context"
atypes "github.com/cortezaproject/corteza/server/automation/types"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
)
var _ wfexec.ExecResponse
type (
corredorHandlerRegistry interface {
AddFunctions(ff ...*atypes.Function)
Type(ref string) expr.Type
}
)
func (h corredorHandler) register() {
h.reg.AddFunctions(
h.Exec(),
)
}
type (
corredorExecArgs struct {
hasScript bool
Script string
hasArgs bool
Args *expr.Vars
}
corredorExecResults struct {
Results *expr.Vars
}
)
// Exec function Corredor automation script executor
//
// expects implementation of exec function:
// func (h corredorHandler) exec(ctx context.Context, args *corredorExecArgs) (results *corredorExecResults, err error) {
// return
// }
func (h corredorHandler) Exec() *atypes.Function {
return &atypes.Function{
Ref: "corredorExec",
Kind: "function",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Corredor automation script executor",
Description: "Executes script in Corredor Automation server",
},
Parameters: []*atypes.Param{
{
Name: "script",
Types: []string{"String"}, Required: true,
},
{
Name: "args",
Types: []string{"Vars"},
},
},
Results: []*atypes.Param{
{
Name: "results",
Types: []string{"Vars"},
},
},
Handler: func(ctx context.Context, in *expr.Vars) (out *expr.Vars, err error) {
var (
args = &corredorExecArgs{
hasScript: in.Has("script"),
hasArgs: in.Has("args"),
}
)
if err = in.Decode(args); err != nil {
return
}
var results *corredorExecResults
if results, err = h.exec(ctx, args); err != nil {
return
}
out = &expr.Vars{}
{
// converting results.Results (*expr.Vars) to Vars
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("Vars").Cast(results.Results); err != nil {
return
} else if err = expr.Assign(out, "results", tval); err != nil {
return
}
}
return
},
}
}