11//go:build !lambdahttpadapter.partial || (lambdahttpadapter.partial && lambdahttpadapter.fiber)
22
3- package fiber
3+ package adapter
44
55import (
66 "context"
@@ -14,13 +14,14 @@ import (
1414 "strings"
1515)
1616
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 "
1818
19- type adapter struct {
20- app * fiber.App
19+ type fiberAdapter struct {
20+ app * fiber.App
21+ handler fasthttp.RequestHandler
2122}
2223
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 {
2425 httpReq := fasthttp .AcquireRequest ()
2526 defer fasthttp .ReleaseRequest (httpReq )
2627
@@ -67,9 +68,9 @@ func (a adapter) adapterFunc(ctx context.Context, r *http.Request, w http.Respon
6768 fctx .Init (httpReq , remoteAddr , nil )
6869 defer fasthttp .ReleaseResponse (& fctx .Response )
6970
70- fctx .SetUserValue (sourceEventUserValueKey , handler . GetSourceEvent ( ctx ) )
71+ fctx .SetUserValue (contextUserValueKey , ctx )
7172
72- a .app . Handler () (& fctx )
73+ a .handler (& fctx )
7374
7475 fctx .Response .Header .VisitAll (func (key , value []byte ) {
7576 k := utils .UnsafeString (key )
@@ -86,10 +87,14 @@ func (a adapter) adapterFunc(ctx context.Context, r *http.Request, w http.Respon
8687 return err
8788}
8889
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
9192}
9293
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 ))
95100}
0 commit comments