dongping1689 2019-07-05 10:58
浏览 154
已采纳

在Google云端功能中找不到软件包“ firebase.google.com/go”

I'm trying to run some example code that stores some random data using a cloud function in the Firestore server, however, Cloud functions deploy command refuses to build the command:

// Package p contains an HTTP Cloud Function.
package p

import (
    //...
    firebase "firebase.google.com/go"
    "log"
    "net/http"
    "os"
)

// Store1 Stores data on FireBase
func Store1(w http.ResponseWriter, r *http.Request) {

    // Use the application default credentials
    ctx := context.Background()

    conf := &firebase.Config{ProjectID: "firefirefire"}
    app, err := firebase.NewApp(ctx, conf)
    if err != nil {
        log.Fatalln(err)
    }

    client, err := app.Firestore(ctx)
    if err != nil {
        log.Fatalln(err)
    }
    defer client.Close()

    _, _, err = client.Collection("users").Add(ctx, map[string]interface{}{
        "first": "Ada",
        "last":  "Lovelace",
        "born":  1815,
    })

    if err != nil {
        log.Fatalf("Failed adding alovelace: %v", err)
    }
    fmt.Println("ENV:" + os.Getenv("VAR1"))
    fmt.Fprint(w, html.EscapeString(d.Message))
}

This is what I get as an error:

localhost:store1 b$ ./deploy.sh
Updated property [functions/region].
Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: /tmp/sgb/gopath/src/serverlessapp/vendor/p/store1.go:6:2: cannot find package "firebase.google.com/go" in any of:
    /tmp/sgb/gopath/src/serverlessapp/vendor/firebase.google.com/go (vendor tree)
    /go/src/firebase.google.com/go (from $GOROOT)
    /tmp/sgb/gopath/src/firebase.google.com/go (from $GOPATH)

As you can see, the problem seems to be that Google doesn't have firebase.google.com/go on Cloud functions engine and as a result I can't have my serverless configuration do the firebase thing. Should I move to CloudSQL and just pay the $11 fee ? Should I continue to try to get Firebase to work? Should I try a Firebase Function instead? Please advise.

  • 写回答

1条回答 默认 最新

  • dongwalun2507 2019-07-05 19:42
    关注

    According to your description and codes,if I understand your issue clearly, you are trying to trigger an HTTP Cloud Function to write data into Cloud Firestore. While you deploy the Cloud Function, package "firebase.google.com/go" cloud not be found.”. Becasue ”firebase.google.com/go” which is the entry point to the Firebase Admin SDK. However, Cloud Function, the Google Cloud Client Library for Go is installed. Based on your requirement, It seems Cloud Functions for Firebase may provide the solution you need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵