读取 APIGatewayProxyRequest 的方法:使用 gin.context
时间:2024-02-08
浏览:396
作者:佚名
有志者,事竟成!如果你在学习Golang,那么本文《读取 APIGatewayProxyRequest 的方法:使用 gin.context》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~
问题内容
我正在使用 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?
}正确答案
我已经找到了解决方案,使用 aws lambda proxy core..
import (
"github.com/awslabs/aws-lambda-go-api-proxy/core"
)
func (ser *Service) GetUserRecordByID(context *gin.Context) {
apiGWRequestContext, ok := core.GetAPIGatewayContextFromContext(c.Request.Context())
}理论要掌握,实操不能落!以上关于《读取 APIGatewayProxyRequest 的方法:使用 gin.context》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.28
热门专题
