英文:
How do I list the cloud functions based on user labels?
问题
我看到在ListFunctions调用中,它返回项目和指定区域中的所有函数。我想按标签进行过滤,但我没有看到ListFunctionsRequest接受过滤器来按标签进行过滤。有什么建议吗?
类似于gcloud CLI支持的方式:https://cloud.google.com/sdk/gcloud/reference/functions/list
文档:https://pkg.go.dev/cloud.google.com/go/functions/apiv1#CloudFunctionsClient.ListFunctions
文档中的代码:
ctx := context.Background()
c, err := functions.NewCloudFunctionsClient(ctx)
if err != nil {
// TODO: 处理错误。
}
defer c.Close()
req := &functionspb.ListFunctionsRequest{
// TODO: 填充请求结构字段。
}
it := c.ListFunctions(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: 处理错误。
}
// TODO: 使用 resp。
_ = resp
}
英文:
I see in the ListFunctions calls, it is returning all the functions in the project and specified region. I would like to filter by labels and I don't see the ListFunctionsRequest accept the filter, to filter it by labels. Any suggestions?
Something like what gcloud CLI supports: https://cloud.google.com/sdk/gcloud/reference/functions/list
Documentation: https://pkg.go.dev/cloud.google.com/go/functions/apiv1#CloudFunctionsClient.ListFunctions
Code from docs
ctx := context.Background()
c, err := functions.NewCloudFunctionsClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &functionspb.ListFunctionsRequest{
// TODO: Fill request struct fields.
}
it := c.ListFunctions(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}```
</details>
# 答案1
**得分**: 1
云函数 API 不支持筛选查询参数。[点击此处](https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/list)查看详细信息。
gcloud 的过滤功能是由命令行界面(CLI)执行的,而不是由 API 执行的。因此,如果你直接使用 API,你需要重新实现这个筛选功能。
<details>
<summary>英文:</summary>
The Cloud Functions API [doesn't support filter query parameter](https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/list)
The gcloud filtering is performed by the CLI and not by the API. Therefore, if you use the API directly, you need to reimplement this filter feature.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论