Skip to content

Commit 25b346a

Browse files
committed
misc: move adapters to parent directory
1 parent 503bab0 commit 25b346a

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !lambdahttpadapter.partial || (lambdahttpadapter.partial && lambdahttpadapter.echo)
22

3-
package echo
3+
package adapter
44

55
import (
66
"context"
@@ -9,15 +9,15 @@ import (
99
"net/http"
1010
)
1111

12-
type adapter struct {
12+
type echoAdapter struct {
1313
echo *echo.Echo
1414
}
1515

16-
func (a adapter) adapterFunc(ctx context.Context, r *http.Request, w http.ResponseWriter) error {
16+
func (a echoAdapter) adapterFunc(ctx context.Context, r *http.Request, w http.ResponseWriter) error {
1717
a.echo.ServeHTTP(w, r)
1818
return nil
1919
}
2020

21-
func NewAdapter(delegate *echo.Echo) handler.AdapterFunc {
22-
return adapter{delegate}.adapterFunc
21+
func NewEchoAdapter(delegate *echo.Echo) handler.AdapterFunc {
22+
return echoAdapter{delegate}.adapterFunc
2323
}

adapter/fiber/fiber.go renamed to adapter/fiber.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !lambdahttpadapter.partial || (lambdahttpadapter.partial && lambdahttpadapter.fiber)
22

3-
package fiber
3+
package adapter
44

55
import (
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
}

adapter/vanilla.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build !lambdahttpadapter.partial || (lambdahttpadapter.partial && lambdahttpadapter.vanilla)
2+
3+
package adapter
4+
5+
import (
6+
"context"
7+
"github.com/its-felix/aws-lambda-go-http-adapter/handler"
8+
"net/http"
9+
)
10+
11+
type vanillaAdapter struct {
12+
http.Handler
13+
}
14+
15+
func (a vanillaAdapter) adapterFunc(ctx context.Context, r *http.Request, w http.ResponseWriter) error {
16+
a.ServeHTTP(w, r)
17+
return nil
18+
}
19+
20+
func NewVanillaAdapter(delegate http.Handler) handler.AdapterFunc {
21+
return vanillaAdapter{delegate}.adapterFunc
22+
}

adapter/vanilla/vanilla.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)