@@ -21,6 +21,7 @@ import (
21
21
// creates a proxy response object from the *fiber.Ctx
22
22
type FiberLambda struct {
23
23
core.RequestAccessor
24
+ v2 core.RequestAccessorV2
24
25
app * fiber.App
25
26
}
26
27
@@ -41,6 +42,12 @@ func (f *FiberLambda) Proxy(req events.APIGatewayProxyRequest) (events.APIGatewa
41
42
return f .proxyInternal (fiberRequest , err )
42
43
}
43
44
45
+ // ProxyV2 is just same as Proxy() but for APIGateway HTTP payload v2
46
+ func (f * FiberLambda ) ProxyV2 (req events.APIGatewayV2HTTPRequest ) (events.APIGatewayV2HTTPResponse , error ) {
47
+ fiberRequest , err := f .v2 .ProxyEventToHTTPRequest (req )
48
+ return f .proxyInternalV2 (fiberRequest , err )
49
+ }
50
+
44
51
// ProxyWithContext receives context and an API Gateway proxy event,
45
52
// transforms them into an http.Request object, and sends it to the echo.Echo for routing.
46
53
// It returns a proxy response object generated from the http.ResponseWriter.
@@ -49,6 +56,12 @@ func (f *FiberLambda) ProxyWithContext(ctx context.Context, req events.APIGatewa
49
56
return f .proxyInternal (fiberRequest , err )
50
57
}
51
58
59
+ // ProxyWithContextV2 is just same as ProxyWithContext() but for APIGateway HTTP payload v2
60
+ func (f * FiberLambda ) ProxyWithContextV2 (ctx context.Context , req events.APIGatewayV2HTTPRequest ) (events.APIGatewayV2HTTPResponse , error ) {
61
+ fiberRequest , err := f .v2 .EventToRequestWithContext (ctx , req )
62
+ return f .proxyInternalV2 (fiberRequest , err )
63
+ }
64
+
52
65
func (f * FiberLambda ) proxyInternal (req * http.Request , err error ) (events.APIGatewayProxyResponse , error ) {
53
66
54
67
if err != nil {
@@ -66,6 +79,23 @@ func (f *FiberLambda) proxyInternal(req *http.Request, err error) (events.APIGat
66
79
return proxyResponse , nil
67
80
}
68
81
82
+ func (f * FiberLambda ) proxyInternalV2 (req * http.Request , err error ) (events.APIGatewayV2HTTPResponse , error ) {
83
+
84
+ if err != nil {
85
+ return core .GatewayTimeoutV2 (), core .NewLoggedError ("Could not convert proxy event to request: %v" , err )
86
+ }
87
+
88
+ resp := core .NewProxyResponseWriterV2 ()
89
+ f .adaptor (resp , req )
90
+
91
+ proxyResponse , err := resp .GetProxyResponse ()
92
+ if err != nil {
93
+ return core .GatewayTimeoutV2 (), core .NewLoggedError ("Error while generating proxy response: %v" , err )
94
+ }
95
+
96
+ return proxyResponse , nil
97
+ }
98
+
69
99
func (f * FiberLambda ) adaptor (w http.ResponseWriter , r * http.Request ) {
70
100
// New fasthttp request
71
101
req := fasthttp .AcquireRequest ()
0 commit comments