https://github.com/awslabs/aws-lambda-go-api-proxy
httplam is a library that bind AWS Lambda, AWS API Gateway to net/http
go get -u github.com/aws-serverless-go/httplam
package main
import (
"github.com/aws-serverless-go/httplam"
"net/http"
)
func main() {
m := http.NewServeMux()
m.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("welcome"))
})
if httplam.IsLambdaRuntime() {
httplam.StartLambdaWithAPIGateway(m)
} else {
http.ListenAndServe(":3000", m)
}
}
package main
import (
"fmt"
"github.com/aws-serverless-go/httplam"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
if httplam.IsLambdaRuntime() {
httplam.StartLambdaWithAPIGateway(router)
} else {
log.Fatal(http.ListenAndServe(":8080", router))
}
}
package main
import (
"github.com/aws-serverless-go/httplam"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"net/http"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("welcome"))
})
if httplam.IsLambdaRuntime() {
httplam.StartLambdaWithAPIGateway(r)
} else {
http.ListenAndServe(":3000", r)
}
}