forked from akrylysov/algnhsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apigw.go
43 lines (36 loc) · 1.25 KB
/
apigw.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
package algnhsa
import (
"context"
"encoding/json"
"errors"
"path"
"github.com/aws/aws-lambda-go/events"
)
var (
errAPIGatewayUnexpectedRequest = errors.New("expected APIGatewayProxyRequest event")
)
func newAPIGatewayRequest(ctx context.Context, payload []byte, opts *Options) (lambdaRequest, error) {
var event events.APIGatewayProxyRequest
if err := json.Unmarshal(payload, &event); err != nil {
return lambdaRequest{}, err
}
if event.RequestContext.AccountID == "" {
return lambdaRequest{}, errAPIGatewayUnexpectedRequest
}
req := lambdaRequest{
HTTPMethod: event.HTTPMethod,
Path: event.Path,
QueryStringParameters: event.QueryStringParameters,
MultiValueQueryStringParameters: event.MultiValueQueryStringParameters,
Headers: event.Headers,
MultiValueHeaders: event.MultiValueHeaders,
Body: event.Body,
IsBase64Encoded: event.IsBase64Encoded,
SourceIP: event.RequestContext.Identity.SourceIP,
Context: newProxyRequestContext(ctx, event),
}
if opts.UseProxyPath {
req.Path = path.Join("/", event.PathParameters["proxy"])
}
return req, nil
}