/
request.go
98 lines (75 loc) · 2.49 KB
/
request.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
package executor
import (
"encoding/json"
"fmt"
)
// Request defines the body of async forward request to faasflow
type Request struct {
Sign string `json: "sign"` // request signature
ID string `json: "id"` // request ID
Query string `json: "query"` // query string
CallbackUrl string `json: "callback-url"` // callback url
ExecutionState string `json: "state"` // Execution State (execution position / execution vertex)
Data []byte `json: "data"` // Partial execution data
// (empty if intermediate_storage enabled
ContextStore map[string][]byte `json: "store"` // Context State for default DataStore
// (empty if external Store is used)
}
func buildRequest(id string,
state string,
query string,
data []byte,
contextState map[string][]byte,
sign string) *Request {
fmt.Println("sdk/executor/request.go: buildRequest start")
request := &Request{
Sign: sign,
ID: id,
ExecutionState: state,
Query: query,
Data: data,
ContextStore: contextState,
}
fmt.Println("sdk/executor/request.go: buildRequest end")
return request
}
func decodeRequest(data []byte) (*Request, error) {
fmt.Println("sdk/executor/request.go: decodeRequest start")
request := &Request{}
err := json.Unmarshal(data, request)
if err != nil {
return nil, err
}
fmt.Println("sdk/executor/request.go: decodeRequest end")
return request, nil
}
func (req *Request) encode() ([]byte, error) {
fmt.Println("sdk/executor/request.go: encode start")
fmt.Println("sdk/executor/request.go: encode end")
return json.Marshal(req)
}
func (req *Request) getData() []byte {
fmt.Println("sdk/executor/request.go: getData start")
fmt.Println("sdk/executor/request.go: getData end")
return req.Data
}
func (req *Request) getID() string {
fmt.Println("sdk/executor/request.go: getID start")
fmt.Println("sdk/executor/request.go: getID end")
return req.ID
}
func (req *Request) getExecutionState() string {
fmt.Println("sdk/executor/request.go: getExecutionState start")
fmt.Println("sdk/executor/request.go: getExecutionState end")
return req.ExecutionState
}
func (req *Request) getContextStore() map[string][]byte {
fmt.Println("sdk/executor/request.go: getContextStore start")
fmt.Println("sdk/executor/request.go: getContextStore end")
return req.ContextStore
}
func (req *Request) getQuery() string {
fmt.Println("sdk/executor/request.go: getQuery start")
fmt.Println("sdk/executor/request.go: getQuery end")
return req.Query
}