登录
首页 >  Golang >  Go问答

使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:先决条件检查失败。,failedPrecondition”

来源:stackoverflow

时间:2024-05-01 12:33:37 408浏览 收藏

今日不肯埋头,明日何以抬头!每日一句努力自己的话哈哈~哈喽,今天我将给大家带来一篇《使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:先决条件检查失败。,failedPrecondition”》,主要内容是讲解等等,感兴趣的朋友可以收藏或者有更好的建议在评论提出,我都会认真看的!大家一起进步,一起学习!

问题内容

我正在尝试使用 google 的 go 客户端包部署 google cloud function。

(https://pkg.go.dev/google.golang.org/api/cloudfunctions/v1?tab=doc#pkg-overview)

我已将其分解为我认为最相关的片段:

import (
    "context"
    log "github.com/sirupsen/logrus"
    functions "google.golang.org/api/cloudfunctions/v1"
)

func main() {
    ctx := context.background()
    cloudfunctionservice, err := functions.newservice(ctx)
    if err != nil {
        log.printf("error at functions.newservice(ctx): \"%v\"\n", err)
    }
    functionspec := functions.cloudfunction{
            entrypoint:        "deploythisfunctionentrypoint",
            eventtrigger: &functions.eventtrigger{
                eventtype: "google.pubsub.topic.publish",
                resource:  "projects/mytestproject/topics/cloud-builds",
            },
            name:                "deploythisfunction",
            runtime:             "go111",
            sourcerepository:    &functions.sourcerepository{url: "https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//"},
    }
    cloudfunctiondeploymentservice := functions.newprojectslocationsfunctionsservice(cloudfunctionservice)
    createcall := cloudfunctiondeploymentservice.create("projects/mytestproject/locations/us-central1", &functionspec)
    resp, err := createcall.context(ctx).do()
    if err != nil {
        log.printf("error at createcall.context(ctx).do(): \"%v\"\n", err)
    }
    log.printf("response createcall.context(ctx).do(): \"%v\"\n", resp)
}

但是,无论我如何格式化它,还是尝试一下。我总是收到以下消息:

googleapi: error 400: precondition check failed., failedprecondition

通过 google api explorer,我使用他们的身份验证和 json 方案运行了请求,并且收到了相同的错误。

https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/create

回应:

{
  "error": {
    "code": 400,
    "message": "Precondition check failed.",
    "status": "FAILED_PRECONDITION"
  }
}

我不知道出了什么问题。我已经开始了自己的项目并且是管理员。当使用 gcp 运行 go 客户端的另一部分(例如创建存储、iam 用户、服务帐户、数据库)时,我可以使其工作并创建这些资源。

如果有人遇到这个问题,我将不胜感激。


解决方案


eventType 应匹配模式:providers/*/eventTypes/*.*。

例如:providers/cloud.pubsub/eventTypes/topic.publish

SourceRepository url 也应为 https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/ 并且您有 https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//

错误消息表明您配置 FunctionSpec 的方式存在问题,我怀疑 EventTriggerSourceRepository 字段。

编辑

code: 400 是一个错误的请求,客户端错误,在本例中是格式问题,首先要检查的是每个 cloud function fileds

本篇关于《使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:先决条件检查失败。,failedPrecondition”》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>