我在firestore Go Docs中看到了类似的示例。我们应该为每个要存储的操作创建一个如下所示的客户端,还是可以在应用程序启动期间创建一个客户端并使用同一客户端执行操作?请告诉我。
ctx := context.Background()
client, err := firestore.NewClient(ctx, "project-id")
if err != nil {
// TODO: Handle error.
}
defer client.Close()
type State struct {
Capital string `firestore:"capital"`
Population float64 `firestore:"pop"` // in millions
}
wr, err := client.Doc("States/Colorado").Create(ctx, State{
Capital: "Denver",
Population: 5.5,
})
if err != nil {
// TODO: Handle error.
}
fmt.Println(wr.UpdateTime)
最佳答案
否。创建一次客户端,然后重新使用同一客户端。有关此帖子的更多详细信息-Should a Firestore client be created per a request with Google App Engine?
关于firebase - 为要存储的每个操作创建新客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61848173/