我是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)
}
使用该代码(来自官方文档),我在数据库客户端初始化时遇到了错误:
无效的数据库 URL: 需要主机: .firebaseio.com
然后我尝试了请求的url:mydb.firebaseio.com->我遇到了另一个错误,告诉我我的数据库不在该区域,并给了我以前的数据库地址。
我还尝试了其他方法,例如 mydb.europe-west1.firebaseio.com 但在这里它说我的证书对于这个网址无效...
我有点迷茫。我知道这个问题与我创建时选择的数据库的本地化有关,但我不明白如何使用go实现来处理它。
缥缈止盈
相关分类