Debian Codegraph @

firestore/examples/end2end/src/apimethods/commit.go

raw
1 package apimethods
2
3 import (
4 "context"
5 "environment"
6 "fmt"
7 "fsutils"
8
9 firestore "go-genproto/googleapis/firestore/v1beta1"
10 )
11
12 //Commit ... Hitting Commit API
13 func Commit() {
14 fmt.Println("\n:: Hitting Commit API ::\n")
15 client, conn := fsutils.MakeFSClient()
16
17 defer conn.Close()
18
19 env := environment.GetEnvironment()
20
21 if env == nil {
22 fmt.Println("\nNo transaction to commit, returning...")
23 return
24 }
25
26 transactionId := env.TransactionId
27
28 commitReq := firestore.CommitRequest{
29 Database: "projects/firestoretestclient/databases/(default)",
30 Transaction: transactionId,
31 }
32 resp, err := client.Commit(context.Background(), &commitReq)
33
34 if err != nil {
35 fmt.Println(err)
36 return
37 }
38 environment.ClearEnvironment()
39 fmt.Println("Successful commit! ", resp)
40 }