Firebase Go 想要主机“firebaseio.com”

JM4*_*445 2 go firebase-realtime-database

我是 firebase 的新手,我正在尝试使用 Go 中的简单数据库设置一个小测试。我在数据库连接方面遇到了很多困难。这是我的代码:

tx := context.Background()
conf := &firebase.Config{
    DatabaseURL: "https://mydb.europe-west1.firebasedatabase.app",
}
// Fetch the service account key JSON file contents
opt := option.WithCredentialsFile("./fireBasePrivateKey.json")

// Initialize the app with a service account, granting admin privileges
app, err := firebase.NewApp(ctx, conf, opt)
if err != nil {
    log.Fatalln("Error initializing app:", err)
}

client, err := app.Database(ctx)
if err != nil {
    log.Fatalln("Error initializing database client:", err)
}
Run Code Online (Sandbox Code Playgroud)

使用该代码(来自官方文档),我在数据库客户端初始化时遇到错误:

无效的数据库 URL:需要主机:.firebaseio.com

然后我尝试使用请求的 url:mydb.firebaseio.com -> 我收到另一个错误,告诉我我的数据库不在该区域,并给了我以前的数据库地址。

我还尝试了其他东西,例如 mydb.europe-west1.firebaseio.com 但这里它说我的证书对该网址无效...

我有点失落。我知道问题与我创建数据库时选择的数据库的本地化有关,但我不明白如何使用 go 实现来处理它。

Fra*_*len 5

<projectname>.firebaseio.com直到去年初,该格式一直是 Firebase 数据库 URL 的唯一格式。如今,美国的数据库仍然使用该格式,但其他地区的数据库使用<dbname><region>.firebasedatabase.app您拥有的格式。

PR #423中添加了对新 URL 格式的支持,并在 6 月份发布的Go Admin SDK 4.6 版本中发布。升级到此版本(或更高版本),以确保您不再收到错误消息。