From 8d9388ccacef12b94fa269a9a8a28bcf8e6ca0a2 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Sat, 19 Sep 2020 19:23:31 +0900 Subject: [PATCH] reuse runtimeAPIClient.buffer --- lambda/runtime_api_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambda/runtime_api_client.go b/lambda/runtime_api_client.go index 44002cdd..8d68be54 100644 --- a/lambda/runtime_api_client.go +++ b/lambda/runtime_api_client.go @@ -90,15 +90,15 @@ func (c *runtimeAPIClient) next() (*invoke, error) { return nil, fmt.Errorf("failed to GET %s: got unexpected status code: %d", url, resp.StatusCode) } - body := bytes.NewBuffer(nil) - _, err = io.Copy(body, resp.Body) + c.buffer.Reset() + _, err = c.buffer.ReadFrom(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read the invoke payload: %v", err) } return &invoke{ id: resp.Header.Get(headerAWSRequestID), - payload: body.Bytes(), + payload: c.buffer.Bytes(), headers: resp.Header, client: c, }, nil