I have golang lambda that prepares ES request, send it to external system and returns its response. Currently, I haven't found a better approach than an unmarshalling response to interface{}
.
func HandleRequest(ctx context.Context, searchRequest SearchRequest) (interface{}, error) {
// ... some data preparation and client initalisation
resp, err := ctxhttp.Post(ctx, &client, url, "application/json", buffer)
if err != nil {
return "", err
}
var k interface{}
all, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(all, &k)
return k, err
}
I'm not sure it is the fastest and the most performant way to forward response due to that extra ReadAll
and Unmarshall
. Is there a more performant approach?
I looked at events.APIGatewayProxyResponse{}
, but body
in it - string and same manipulations are needed