MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Invoke

Method Invoke

pkg/controller/client/rpc.go:54–107  ·  view source on GitHub ↗
(ir *api.InvokeRequest)

Source from the content-addressed store, hash-verified

52}
53
54func (c *ControllerClient) Invoke(ir *api.InvokeRequest) (response *api.InvokeResponse, err error) {
55 response = api.NewInvokeResponse()
56 req := fasthttp.AcquireRequest()
57
58 endpoint := c.host
59 if c.prefix != "" {
60 endpoint += c.prefix
61 }
62 p := fmt.Sprintf("%s://%s/%s/functions/%s/invocations", c.scheme, endpoint, c.version, ir.FunctionBRN)
63 //添加query参数
64 if ir.Queries != nil && len(ir.Queries.Encode()) > 0 {
65 p += "?" + ir.Queries.Encode()
66 }
67 req.SetRequestURI(p)
68
69 if ir.Headers != nil {
70 for k, v := range ir.Headers {
71 req.Header.Set(k, v)
72 }
73 }
74 req.Header.SetHost(c.host)
75 req.Header.SetMethod("POST")
76 req.Header.SetContentType("application/json")
77 req.Header.Set(api.HeaderXRequestID, ir.RequestID)
78 req.Header.Set(api.HeaderXAccountID, ir.UserID)
79 if ir.Authorization != "" {
80 req.Header.Set(api.HeaderAuthorization, ir.Authorization)
81 }
82 req.Header.Set(api.HeaderInvokeType, ir.InvokeType)
83 req.Header.Set(api.BceFaasTriggerKey, ir.TriggerType)
84 req.Header.Set(api.HeaderLogType, string(ir.LogType))
85 if ir.LogToBody {
86 req.Header.Set(api.HeaderLogToBody, "true")
87 }
88 if ir.Body != nil {
89 req.SetBodyString(*ir.Body)
90 }
91
92 if ir.Body != nil {
93 req.SetBodyString(*ir.Body)
94 }
95 resp, err := c.client.Do(req)
96 if err != nil {
97 logs.Errorf("unexpected minikun client error: %s", err)
98 // TODO: handler unexpected error
99 return
100 }
101 response.SetStatusCode(resp.StatusCode())
102 response.SetBody(resp.Body())
103 resp.Header.VisitAll(func(key, value []byte) {
104 response.SetHeader(string(key), string(value))
105 })
106 return
107}
108
109func (c *ControllerClient) ListRuntimes() ([]*rtctrl.RuntimeInfo, error) {
110 rts := make([]*rtctrl.RuntimeInfo, 0)

Callers 1

TestInvokeFunction · 0.95

Calls 11

NewInvokeResponseFunction · 0.92
ErrorfFunction · 0.92
SetHostMethod · 0.80
EncodeMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
SetStatusCodeMethod · 0.45
StatusCodeMethod · 0.45
SetBodyMethod · 0.45
BodyMethod · 0.45
SetHeaderMethod · 0.45

Tested by 1

TestInvokeFunction · 0.76