gpt4 book ai didi

go - 如何使用 Go API 客户端以编程方式创建 Google Cloud Function

转载 作者:IT王子 更新时间:2023-10-29 02:31:02 25 4
gpt4 key购买 nike

有一个用于与 Cloud Functions API 交互的 Go 包 (google.golang.org/api/cloudfunctions/v1),但我不知道如何使用它来创建新函数。尝试上传到 Cloud Storage 存储桶的签名 URL 时收到 404 和 403 错误。

有人知道如何使用这个包来部署 Cloud Functions 吗?

最佳答案

我在使用google.golang.org/api/cloudfunctions/v1的时候遇到过类似的问题,我遇到的第一个 403 错误问题是由于使用 auth 客户端使用预先签名的生成上传 URL,使用裸 http 客户端有帮助

httpClient := http.DefaultClient
data, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
request, err := http.NewRequest("PUT", uploadURL, bytes.NewReader(data))
if err != nil {
return err
}
request.Header.Set("content-type", "application/zip")
request.Header.Set("x-goog-content-length-range", "0,104857600")
request.Header.Set("Content-Length", fmt.Sprintf("%d", len(data)))
response, err := httpClient.Do(request)
if err != nil {
return err
}

我看到的另一个 404 问题是当我使用位置作为区域而不是下面代码段中显示的完全限定名称时

var location =  'projects/${projectID}/locations/${region}'  
projectService := cloudfunctions.NewProjectsLocationsFunctionsService(ctxClient.service)
createCall := projectService.Create(location, request.CloudFunction)
createCall.Context(ctxClient.Context())
return createCall.Do()
h

你也可以在这个项目中查看golang cloud functions google.golang.org/api/cloudfunctions/v1 API使用情况:

Cloud function service

关于go - 如何使用 Go API 客户端以编程方式创建 Google Cloud Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54447975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com