如何使用 AWS lambda 函数获取 URL 参数?

我正在为 API 使用 Netlify 函数,除了我需要访问 URL 参数时,其中大部分都可以正常工作


这是我必须获取参数的片段:


func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {


    id := request.PathParameters["id"]


    ...

}


func main() {

    lambda.Start(Handler)

}

我有其他功能正常工作,不需要 URL 参数,但无法弄清楚如何让这些功能正常工作,我尝试了多种不同的选择:


https://example.com/endpoint/1

https://example.com/endpoint/id=1

https://example.com/endpoint?id=1

以上均未在命中端点时返回 id 路径参数


呼如林
浏览 263回答 1
1回答

守着星空守着你

您可以使用request.QueryStringParameters["id"]从查询参数中获取 idfunc Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {    id := request.QueryStringParameters["id"]    ...}并打电话给https://example.com/endpoint?id=1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go