go - 如何使用 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 路径参数
解决方案
您可以使用request.QueryStringParameters["id"]
从查询参数中获取 id
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.QueryStringParameters["id"]
...
}
并打电话给https://example.com/endpoint?id=1
推荐阅读
- angular - 离子模态超过材料日期选择器?
- sql - 在sql中合并内部连接返回的列
- macos - 通过 anaconda 安装 python 3.8 的“解决环境”失败
- c# - 我如何才能重构多个只有条件
- spring-boot - spring security OIDC keycloak 无法获取权限和应用授权
- html - 带有展开/折叠动画的平行四边形(Warframe 参考)
- kubernetes - Prometheus 目标端点 IP 位置
- python - 如何动态地将列表附加到主 URL
- java - spring boot jar 神器运行出现问题
- blazor - Blazor 文档中的代码引发异常。细节在描述中