如何使用Golang从Firebase获取数据。

huangapple go评论119阅读模式
英文:

how to fetch from firebase using golang

问题

数据库结构
我想使用Golang检索存储在这个数据库中的所有数据

  1. {
  2. "-KaMY9JKmgyRWVApfcXW": {
  3. "EmailId": "aaa@gmail.com",
  4. "FirstName": "abc",
  5. "LastName": "xyz",
  6. "UserType": "user"
  7. }
  8. }
英文:

Database structure
I want to retrieve all the data stored in this database using Golang

  1. {
  2. "-KaMY9JKmgyRWVApfcXW": {
  3. "EmailId": "aaa@gmail.com",
  4. "FirstName": "abc",
  5. "LastName": "xyz",
  6. "UserType": "user"
  7. }
  8. }

答案1

得分: 0

v := map[string]YourStruct{}
err := dB.Child("YourChild").Value(&v)
if err != nil {
log.Fatal(err)
}
fmt.Println("%s\n", v)

这段代码是使用YourStruct{}结构体来获取值的示例。YourChild是上述代码中的子节点名称。

英文:
  1. v := map[string]YourStruct{}
  2. err := dB.Child("YourChild").Value(&v)
  3. if err != nil {
  4. log.Fatal(err)
  5. }
  6. fmt.Println("%s\n", v)

Where YourStruct{} is the struct which you use for fetching values. YourChild is the child name of your above code.

huangapple
  • 本文由 发表于 2017年1月17日 17:02:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/41692888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定