如何根据用户标签列出云函数?

huangapple go评论82阅读模式
英文:

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&#39;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>



huangapple
  • 本文由 发表于 2021年6月12日 07:51:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/67944518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定