Skip to content
Closed
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down