为了账号安全,请及时绑定邮箱和手机立即绑定

从 gin.context 读取 APIGatewayProxyRequest

从 gin.context 读取 APIGatewayProxyRequest

Go
慕尼黑的夜晚无繁华 2022-12-13 10:59:35
我正在使用 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? }
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

我找到了解决方案,使用 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())

}


查看完整回答
反对 回复 2022-12-13
  • 1 回答
  • 0 关注
  • 177 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号