当前位置: > > > > 如何使用 AWS lambda 函数获取 URL 参数?
来源:stackoverflow
2024-04-24 13:12:32
0浏览
收藏
哈喽!今天心血来潮给大家带来了《如何使用 AWS lambda 函数获取 URL 参数?》,想必大家应该对Golang都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到,若是你正在学习Golang,千万别错过这篇文章~希望能帮助到你!
问题内容
我正在为 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
今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注公众号,一起学习编程~