1
1
//go:build !lambdahttpadapter.partial || (lambdahttpadapter.partial && lambdahttpadapter.fiber)
2
2
3
- package fiber
3
+ package adapter
4
4
5
5
import (
6
6
"context"
@@ -14,13 +14,14 @@ import (
14
14
"strings"
15
15
)
16
16
17
- const sourceEventUserValueKey = "github.com/its-felix/aws-lambda-go-adapter- fiber::sourceEvent "
17
+ const contextUserValueKey = "github.com/its-felix/aws-lambda-go-http-adapter/adapter/ fiber::contextUserValueKey "
18
18
19
- type adapter struct {
20
- app * fiber.App
19
+ type fiberAdapter struct {
20
+ app * fiber.App
21
+ handler fasthttp.RequestHandler
21
22
}
22
23
23
- func (a adapter ) adapterFunc (ctx context.Context , r * http.Request , w http.ResponseWriter ) error {
24
+ func (a fiberAdapter ) adapterFunc (ctx context.Context , r * http.Request , w http.ResponseWriter ) error {
24
25
httpReq := fasthttp .AcquireRequest ()
25
26
defer fasthttp .ReleaseRequest (httpReq )
26
27
@@ -67,9 +68,9 @@ func (a adapter) adapterFunc(ctx context.Context, r *http.Request, w http.Respon
67
68
fctx .Init (httpReq , remoteAddr , nil )
68
69
defer fasthttp .ReleaseResponse (& fctx .Response )
69
70
70
- fctx .SetUserValue (sourceEventUserValueKey , handler . GetSourceEvent ( ctx ) )
71
+ fctx .SetUserValue (contextUserValueKey , ctx )
71
72
72
- a .app . Handler () (& fctx )
73
+ a .handler (& fctx )
73
74
74
75
fctx .Response .Header .VisitAll (func (key , value []byte ) {
75
76
k := utils .UnsafeString (key )
@@ -86,10 +87,14 @@ func (a adapter) adapterFunc(ctx context.Context, r *http.Request, w http.Respon
86
87
return err
87
88
}
88
89
89
- func NewAdapter (delegate * fiber.App ) handler.AdapterFunc {
90
- return adapter {delegate }.adapterFunc
90
+ func NewFiberAdapter (delegate * fiber.App ) handler.AdapterFunc {
91
+ return fiberAdapter {delegate , delegate . Handler () }.adapterFunc
91
92
}
92
93
93
- func GetSourceEvent (ctx * fiber.Ctx ) any {
94
- return ctx .Context ().UserValue (sourceEventUserValueKey )
94
+ func GetContextFiber (ctx * fiber.Ctx ) context.Context {
95
+ return ctx .Context ().Value (contextUserValueKey ).(context.Context )
96
+ }
97
+
98
+ func GetSourceEventFiber (ctx * fiber.Ctx ) any {
99
+ return handler .GetSourceEvent (GetContextFiber (ctx ))
95
100
}
0 commit comments