猿问

从 gin.context 读取 APIGatewayProxyRequest

我正在使用 github.com/awslabs/aws-lambda-go-api-proxy/gin 创建 API。如果可能的话,我想从 gin.Context 中读取 APIGatewayProxyRequest 或者请建议其他更好的方法?这是我的请求处理程序,


func handleRequest(ctx context.Context, req *events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {

    db := persistence.InitializeDB()

    defer db.Close()


    router := router.NewApiRouter()


    if ginLambda == nil {

        ginLambda = gin.New(router.Initialize()) // here I send req to router, which I want to use in endpoint handler

    }


    response, err := ginLambda.ProxyWithContext(ctx, *req)


   ...


    return response, err

}

这是我的发布请求处理程序,


func (ser *Service) GetUserRecordByID(context *gin.Context) {

// here I want to read APIGatewayProxyRequest object. I can log context, but not sure how to read APIGatewayProxyRequest object? 

}


慕尼黑的夜晚无繁华
浏览 178回答 1
1回答

森林海

我找到了解决方案,使用 aws lambda 代理核心..import ("github.com/awslabs/aws-lambda-go-api-proxy/core")func (ser *Service) GetUserRecordByID(context *gin.Context) {apiGWRequestContext, ok := core.GetAPIGatewayContextFromContext(c.Request.Context())}
随时随地看视频慕课网APP

相关分类

Go
我要回答