awslabs / aws-lambda-go-api-proxy

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin (https://gin-gonic.github.io/gin/ ) to AWS Lambda and Amazon API Gateway.
Apache License 2.0
1.09k stars 200 forks source link

Echo support? #198

Open algoflows opened 7 months ago

algoflows commented 7 months ago

Does this support Echo framework?

https://echo.labstack.com/

thomasgtaylor commented 6 months ago

Yep! Sure does.

import (
    "net/http"

    "github.com/labstack/echo/v4"
    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
    "github.com/awslabs/aws-lambda-go-api-proxy/echo"
)

var (
    echoLambda *echoadapter.EchoLambdaV2
)

func init() {
    e := echo.New()
    e.GET("test", func(c echo.Context) error {
        return c.String(http.StatusOK, "hello world")
    })
    echoLambda = echoadapter.NewV2(e)
}

func Handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
    return echoLambda.ProxyWithContext(ctx, req)
}

func main() {
    lambda.Start(Handler)
}