doumianfeng6979 2019-01-30 19:16
浏览 14

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

There is a Go package for interacting with the Cloud Functions API (google.golang.org/api/cloudfunctions/v1) but I can't figure out how to use it to create new functions. I'm getting 404 and 403 errors when attempting to upload to the signed URL for the Cloud Storage bucket.

Does anyone know how to use this package to deploy Cloud Functions?

  • 写回答

1条回答 默认 最新

  • dongwo5589 2019-01-31 05:28
    关注

    I have encountered a similar issue when using google.golang.org/api/cloudfunctions/v1, the first problem with 403 error I had, was due to using auth client with presigned Generate Upload URL, using bare http client helped

    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
    }
    

    Another issue I saw with 404 was when I was using location as region as opposed to the fully qualified name presented in the below snippet

    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
    

    You can also check golang cloud functions google.golang.org/api/cloudfunctions/v1 API usage in this project:

    Cloud function service

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助