| 52 | } |
| 53 | |
| 54 | func (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 | |
| 109 | func (c *ControllerClient) ListRuntimes() ([]*rtctrl.RuntimeInfo, error) { |
| 110 | rts := make([]*rtctrl.RuntimeInfo, 0) |