@@ -17,6 +17,7 @@ import (
17
17
// creates a proxy response object from the http.ResponseWriter
18
18
type EchoLambda struct {
19
19
core.RequestAccessor
20
+ v2 core.RequestAccessorV2
20
21
21
22
Echo * echo.Echo
22
23
}
@@ -36,6 +37,12 @@ func (e *EchoLambda) Proxy(req events.APIGatewayProxyRequest) (events.APIGateway
36
37
return e .proxyInternal (echoRequest , err )
37
38
}
38
39
40
+ // ProxyV2 is the same as Proxy(), but for V2 payloads instead
41
+ func (e * EchoLambda ) ProxyV2 (req events.APIGatewayV2HTTPRequest ) (events.APIGatewayV2HTTPResponse , error ) {
42
+ echoRequest , err := e .v2 .ProxyEventToHTTPRequest (req )
43
+ return e .proxyInternalV2 (echoRequest , err )
44
+ }
45
+
39
46
// ProxyWithContext receives context and an API Gateway proxy event,
40
47
// transforms them into an http.Request object, and sends it to the echo.Echo for routing.
41
48
// It returns a proxy response object generated from the http.ResponseWriter.
@@ -44,6 +51,12 @@ func (e *EchoLambda) ProxyWithContext(ctx context.Context, req events.APIGateway
44
51
return e .proxyInternal (echoRequest , err )
45
52
}
46
53
54
+ // ProxyWithContextV2 is the same as ProxyWithContext(), but for V2 payloads instead
55
+ func (e * EchoLambda ) ProxyWithContextV2 (ctx context.Context , req events.APIGatewayV2HTTPRequest ) (events.APIGatewayV2HTTPResponse , error ) {
56
+ echoRequest , err := e .v2 .EventToRequestWithContext (ctx , req )
57
+ return e .proxyInternalV2 (echoRequest , err )
58
+ }
59
+
47
60
func (e * EchoLambda ) proxyInternal (req * http.Request , err error ) (events.APIGatewayProxyResponse , error ) {
48
61
49
62
if err != nil {
@@ -60,3 +73,20 @@ func (e *EchoLambda) proxyInternal(req *http.Request, err error) (events.APIGate
60
73
61
74
return proxyResponse , nil
62
75
}
76
+
77
+ func (e * EchoLambda ) proxyInternalV2 (req * http.Request , err error ) (events.APIGatewayV2HTTPResponse , error ) {
78
+
79
+ if err != nil {
80
+ return core .GatewayTimeoutV2 (), core .NewLoggedError ("Could not convert proxy event to request: %v" , err )
81
+ }
82
+
83
+ respWriter := core .NewProxyResponseWriterV2 ()
84
+ e .Echo .ServeHTTP (http .ResponseWriter (respWriter ), req )
85
+
86
+ proxyResponse , err := respWriter .GetProxyResponse ()
87
+ if err != nil {
88
+ return core .GatewayTimeoutV2 (), core .NewLoggedError ("Error while generating proxy response: %v" , err )
89
+ }
90
+
91
+ return proxyResponse , nil
92
+ }
0 commit comments