登录
首页 >  Golang >  Go问答

读取 APIGatewayProxyRequest 的方法:使用 gin.context

来源:stackoverflow

时间:2024-02-08 09:51:16 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学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>