| 1 |
package apimethods |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"environment" |
| 6 |
"fmt" |
| 7 |
"fsutils" |
| 8 |
firestore "go-genproto/googleapis/firestore/v1beta1" |
| 9 |
) |
| 10 |
|
| 11 |
//BeginTransaction ... Use BeginTransaction API |
| 12 |
func BeginTransaction() { |
| 13 |
fmt.Println("\n:: Starting New Transaction ::\n") |
| 14 |
|
| 15 |
client, conn := fsutils.MakeFSClient() |
| 16 |
|
| 17 |
defer conn.Close() |
| 18 |
|
| 19 |
options := firestore.TransactionOptions{} |
| 20 |
beginTransactionReq := firestore.BeginTransactionRequest{ |
| 21 |
Database: "projects/firestoretestclient/databases/(default)", |
| 22 |
Options: &options, |
| 23 |
} |
| 24 |
resp, err := client.BeginTransaction(context.Background(), &beginTransactionReq) |
| 25 |
|
| 26 |
if err != nil { |
| 27 |
fmt.Println(err) |
| 28 |
return |
| 29 |
} |
| 30 |
transactionId := resp.GetTransaction() |
| 31 |
fmt.Println("Successfully began new transaction", transactionId) |
| 32 |
environment.SetEnvironment(transactionId) |
| 33 |
|
| 34 |
} |