diff --git a/README.md b/README.md index e13a68a..19db116 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,28 @@ func main() { } ``` +#### Gorilla Mux +```golang +package main + +import ( + "net/http" + + "github.com/gorilla/mux" + "github.com/its-felix/aws-lambda-go-http-adapter/adapter" +) + +func main() { + r := mux.NewRouter() + r.Handle("/ping", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){ + w.WriteHeader(http.StatusOK) + w.Write([]byte("pong")) + })) + + adapter := adapter.NewGorillaMuxAdapter(r) +} +``` + ### Creating the Handler #### API Gateway V1 ```golang diff --git a/adapter/gorillamux.go b/adapter/gorillamux.go new file mode 100644 index 0000000..3dc6eb2 --- /dev/null +++ b/adapter/gorillamux.go @@ -0,0 +1,22 @@ +package adapter + +import ( + "context" + "net/http" + + "github.com/gorilla/mux" + "github.com/its-felix/aws-lambda-go-http-adapter/handler" +) + +type gorillaMuxAdapter struct { + router *mux.Router +} + +func (g gorillaMuxAdapter) adapterFunc(ctx context.Context, r *http.Request, w http.ResponseWriter) error { + g.router.ServeHTTP(w, r) + return nil +} + +func NewGorillaMuxAdapter(delegate *mux.Router) handler.AdapterFunc { + return gorillaMuxAdapter{router: delegate}.adapterFunc +} diff --git a/go.mod b/go.mod index e47b31f..4132e91 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.20 require ( github.com/aws/aws-lambda-go v1.47.0 github.com/gofiber/fiber/v2 v2.52.5 + github.com/gorilla/mux v1.8.1 github.com/labstack/echo/v4 v4.12.0 github.com/valyala/fasthttp v1.55.0 ) diff --git a/go.sum b/go.sum index 46ae960..e122691 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yG github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=