/
apigw_body_handler.gen.go
109 lines (91 loc) · 2.2 KB
/
apigw_body_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
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/apigw_body_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/http"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
)
var _ wfexec.ExecResponse
type (
apigwBodyHandlerRegistry interface {
AddFunctions(ff ...*atypes.Function)
Type(ref string) expr.Type
}
)
func (h apigwBodyHandler) register() {
h.reg.AddFunctions(
h.Read(),
)
}
type (
apigwBodyReadArgs struct {
hasRequest bool
Request *http.Request
}
apigwBodyReadResults struct {
Body string
}
)
// Read function Read request body from integration gateway
//
// expects implementation of read function:
// func (h apigwBodyHandler) read(ctx context.Context, args *apigwBodyReadArgs) (results *apigwBodyReadResults, err error) {
// return
// }
func (h apigwBodyHandler) Read() *atypes.Function {
return &atypes.Function{
Ref: "apigwBodyRead",
Kind: "function",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Read request body from integration gateway",
},
Parameters: []*atypes.Param{
{
Name: "request",
Types: []string{"HttpRequest"}, Required: true,
},
},
Results: []*atypes.Param{
{
Name: "body",
Types: []string{"String"},
},
},
Handler: func(ctx context.Context, in *expr.Vars) (out *expr.Vars, err error) {
var (
args = &apigwBodyReadArgs{
hasRequest: in.Has("request"),
}
)
if err = in.Decode(args); err != nil {
return
}
var results *apigwBodyReadResults
if results, err = h.read(ctx, args); err != nil {
return
}
out = &expr.Vars{}
{
// converting results.Body (string) to String
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("String").Cast(results.Body); err != nil {
return
} else if err = expr.Assign(out, "body", tval); err != nil {
return
}
}
return
},
}
}