Skip to content

add gorilla mux adapter #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions adapter/gorillamux.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=