从 gin.context 读取 APIGatewayProxyRequest
Read APIGatewayProxyRequest from 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
}
这是我的 post 请求处理程序,
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 代理核心..
import (
"github.com/awslabs/aws-lambda-go-api-proxy/core"
)
func (ser *Service) GetUserRecordByID(context *gin.Context) {
apiGWRequestContext, ok := core.GetAPIGatewayContextFromContext(c.Request.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
}
这是我的 post 请求处理程序,
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 代理核心..
import (
"github.com/awslabs/aws-lambda-go-api-proxy/core"
)
func (ser *Service) GetUserRecordByID(context *gin.Context) {
apiGWRequestContext, ok := core.GetAPIGatewayContextFromContext(c.Request.Context())
}