【问题标题】:How do I list the cloud functions based on user labels?如何根据用户标签列出云功能?
【发布时间】:2021-08-28 20:10:50
【问题描述】:

我在 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: 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
    }```

【问题讨论】:

  • 我不知道这种情况下的答案。有些 API 支持 filters,有些不支持或不支持所有过滤器用例。如果 CLI 支持过滤器而 API 不支持,则过滤器在 CLI 内实现。这意味着您还需要在代码中复制该过滤功能。要进行验证,请创建一个 CLI 命令并添加命令行选项 --log-http 以查看实际的 REST API 调用。如果过滤器没有传递给 API,那么您知道 a) 您必须编写该过滤器代码,或者 b) 在 API 调用中过滤器是如何编码的。

标签: go google-cloud-platform google-cloud-functions


【解决方案1】:

云函数 API doesn't support filter query parameter

gcloud 过滤由 CLI 而非 API 执行。因此,如果直接使用 API,则需要重新实现此过滤功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    相关资源
    最近更新 更多