| 1 |
package apimethods |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"fsutils" |
| 7 |
"io" |
| 8 |
"userutil" |
| 9 |
|
| 10 |
firestore "go-genproto/googleapis/firestore/v1beta1" |
| 11 |
) |
| 12 |
|
| 13 |
//BatchGetDocuments ... Retrieve all documents from database |
| 14 |
func BatchGetDocuments() { |
| 15 |
fmt.Println("\n:: Batch Retreive Documents ::\n") |
| 16 |
|
| 17 |
client, conn := fsutils.MakeFSClient() |
| 18 |
|
| 19 |
defer conn.Close() |
| 20 |
|
| 21 |
docList := []string{} |
| 22 |
|
| 23 |
for { |
| 24 |
fmt.Print("Enter Document Id (blank when finished): ") |
| 25 |
inp := userutil.ReadFromConsole() |
| 26 |
if inp != "" { |
| 27 |
docList = append(docList, "projects/firestoretestclient/databases/(default)/documents/GrpcTestData/"+inp) |
| 28 |
} else { |
| 29 |
break |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
batchGetDocsReq := firestore.BatchGetDocumentsRequest{ |
| 34 |
Database: "projects/firestoretestclient/databases/(default)", |
| 35 |
Documents: docList, |
| 36 |
} |
| 37 |
|
| 38 |
stream, err := client.BatchGetDocuments(context.Background(), &batchGetDocsReq) |
| 39 |
|
| 40 |
if err != nil { |
| 41 |
fmt.Println(err) |
| 42 |
return |
| 43 |
} |
| 44 |
for { |
| 45 |
resp, err := stream.Recv() |
| 46 |
if err == io.EOF { |
| 47 |
break |
| 48 |
} |
| 49 |
if err != nil { |
| 50 |
fmt.Println(err) |
| 51 |
} |
| 52 |
userutil.DrawDocument(*resp.GetFound()) |
| 53 |
} |
| 54 |
|
| 55 |
} |