有一个用于与Cloud functions API (google.golang.org/api/cloudfunctions/v1)交互的Go包,但我不知道如何使用它来创建新函数。当我尝试上传到云存储存储桶的签名URL时,收到404和403错误。
有人知道如何使用这个包来部署云函数吗?
发布于 2019-01-31 13:28:55
我在使用google.golang.org/api/cloudfunctions/v1时遇到了类似的问题,我遇到的第一个问题是403错误,这是由于使用带有预签名的生成上传URL的auth客户端,使用纯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 /cloudfunction/v1 API使用情况:
https://stackoverflow.com/questions/54447975
复制相似问题