我正在将Netlify函数用于API,除了需要访问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 path参数
答案 0 :(得分:1)
您可以使用request.QueryStringParameters["id"]
从查询参数中获取ID
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.QueryStringParameters["id"]
...
}
然后像https://example.com/endpoint?id=1