You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

329 lines
6.2 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by gapic-generator. DO NOT EDIT.
  15. package firestore_test
  16. import (
  17. "context"
  18. "io"
  19. firestore "cloud.google.com/go/firestore/apiv1"
  20. "google.golang.org/api/iterator"
  21. firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
  22. )
  23. func ExampleNewClient() {
  24. ctx := context.Background()
  25. c, err := firestore.NewClient(ctx)
  26. if err != nil {
  27. // TODO: Handle error.
  28. }
  29. // TODO: Use client.
  30. _ = c
  31. }
  32. func ExampleClient_GetDocument() {
  33. ctx := context.Background()
  34. c, err := firestore.NewClient(ctx)
  35. if err != nil {
  36. // TODO: Handle error.
  37. }
  38. req := &firestorepb.GetDocumentRequest{
  39. // TODO: Fill request struct fields.
  40. }
  41. resp, err := c.GetDocument(ctx, req)
  42. if err != nil {
  43. // TODO: Handle error.
  44. }
  45. // TODO: Use resp.
  46. _ = resp
  47. }
  48. func ExampleClient_ListDocuments() {
  49. ctx := context.Background()
  50. c, err := firestore.NewClient(ctx)
  51. if err != nil {
  52. // TODO: Handle error.
  53. }
  54. req := &firestorepb.ListDocumentsRequest{
  55. // TODO: Fill request struct fields.
  56. }
  57. it := c.ListDocuments(ctx, req)
  58. for {
  59. resp, err := it.Next()
  60. if err == iterator.Done {
  61. break
  62. }
  63. if err != nil {
  64. // TODO: Handle error.
  65. }
  66. // TODO: Use resp.
  67. _ = resp
  68. }
  69. }
  70. func ExampleClient_CreateDocument() {
  71. ctx := context.Background()
  72. c, err := firestore.NewClient(ctx)
  73. if err != nil {
  74. // TODO: Handle error.
  75. }
  76. req := &firestorepb.CreateDocumentRequest{
  77. // TODO: Fill request struct fields.
  78. }
  79. resp, err := c.CreateDocument(ctx, req)
  80. if err != nil {
  81. // TODO: Handle error.
  82. }
  83. // TODO: Use resp.
  84. _ = resp
  85. }
  86. func ExampleClient_UpdateDocument() {
  87. ctx := context.Background()
  88. c, err := firestore.NewClient(ctx)
  89. if err != nil {
  90. // TODO: Handle error.
  91. }
  92. req := &firestorepb.UpdateDocumentRequest{
  93. // TODO: Fill request struct fields.
  94. }
  95. resp, err := c.UpdateDocument(ctx, req)
  96. if err != nil {
  97. // TODO: Handle error.
  98. }
  99. // TODO: Use resp.
  100. _ = resp
  101. }
  102. func ExampleClient_DeleteDocument() {
  103. ctx := context.Background()
  104. c, err := firestore.NewClient(ctx)
  105. if err != nil {
  106. // TODO: Handle error.
  107. }
  108. req := &firestorepb.DeleteDocumentRequest{
  109. // TODO: Fill request struct fields.
  110. }
  111. err = c.DeleteDocument(ctx, req)
  112. if err != nil {
  113. // TODO: Handle error.
  114. }
  115. }
  116. func ExampleClient_BatchGetDocuments() {
  117. ctx := context.Background()
  118. c, err := firestore.NewClient(ctx)
  119. if err != nil {
  120. // TODO: Handle error.
  121. }
  122. req := &firestorepb.BatchGetDocumentsRequest{
  123. // TODO: Fill request struct fields.
  124. }
  125. stream, err := c.BatchGetDocuments(ctx, req)
  126. if err != nil {
  127. // TODO: Handle error.
  128. }
  129. for {
  130. resp, err := stream.Recv()
  131. if err == io.EOF {
  132. break
  133. }
  134. if err != nil {
  135. // TODO: handle error.
  136. }
  137. // TODO: Use resp.
  138. _ = resp
  139. }
  140. }
  141. func ExampleClient_BeginTransaction() {
  142. ctx := context.Background()
  143. c, err := firestore.NewClient(ctx)
  144. if err != nil {
  145. // TODO: Handle error.
  146. }
  147. req := &firestorepb.BeginTransactionRequest{
  148. // TODO: Fill request struct fields.
  149. }
  150. resp, err := c.BeginTransaction(ctx, req)
  151. if err != nil {
  152. // TODO: Handle error.
  153. }
  154. // TODO: Use resp.
  155. _ = resp
  156. }
  157. func ExampleClient_Commit() {
  158. ctx := context.Background()
  159. c, err := firestore.NewClient(ctx)
  160. if err != nil {
  161. // TODO: Handle error.
  162. }
  163. req := &firestorepb.CommitRequest{
  164. // TODO: Fill request struct fields.
  165. }
  166. resp, err := c.Commit(ctx, req)
  167. if err != nil {
  168. // TODO: Handle error.
  169. }
  170. // TODO: Use resp.
  171. _ = resp
  172. }
  173. func ExampleClient_Rollback() {
  174. ctx := context.Background()
  175. c, err := firestore.NewClient(ctx)
  176. if err != nil {
  177. // TODO: Handle error.
  178. }
  179. req := &firestorepb.RollbackRequest{
  180. // TODO: Fill request struct fields.
  181. }
  182. err = c.Rollback(ctx, req)
  183. if err != nil {
  184. // TODO: Handle error.
  185. }
  186. }
  187. func ExampleClient_RunQuery() {
  188. ctx := context.Background()
  189. c, err := firestore.NewClient(ctx)
  190. if err != nil {
  191. // TODO: Handle error.
  192. }
  193. req := &firestorepb.RunQueryRequest{
  194. // TODO: Fill request struct fields.
  195. }
  196. stream, err := c.RunQuery(ctx, req)
  197. if err != nil {
  198. // TODO: Handle error.
  199. }
  200. for {
  201. resp, err := stream.Recv()
  202. if err == io.EOF {
  203. break
  204. }
  205. if err != nil {
  206. // TODO: handle error.
  207. }
  208. // TODO: Use resp.
  209. _ = resp
  210. }
  211. }
  212. func ExampleClient_Write() {
  213. ctx := context.Background()
  214. c, err := firestore.NewClient(ctx)
  215. if err != nil {
  216. // TODO: Handle error.
  217. }
  218. stream, err := c.Write(ctx)
  219. if err != nil {
  220. // TODO: Handle error.
  221. }
  222. go func() {
  223. reqs := []*firestorepb.WriteRequest{
  224. // TODO: Create requests.
  225. }
  226. for _, req := range reqs {
  227. if err := stream.Send(req); err != nil {
  228. // TODO: Handle error.
  229. }
  230. }
  231. stream.CloseSend()
  232. }()
  233. for {
  234. resp, err := stream.Recv()
  235. if err == io.EOF {
  236. break
  237. }
  238. if err != nil {
  239. // TODO: handle error.
  240. }
  241. // TODO: Use resp.
  242. _ = resp
  243. }
  244. }
  245. func ExampleClient_Listen() {
  246. ctx := context.Background()
  247. c, err := firestore.NewClient(ctx)
  248. if err != nil {
  249. // TODO: Handle error.
  250. }
  251. stream, err := c.Listen(ctx)
  252. if err != nil {
  253. // TODO: Handle error.
  254. }
  255. go func() {
  256. reqs := []*firestorepb.ListenRequest{
  257. // TODO: Create requests.
  258. }
  259. for _, req := range reqs {
  260. if err := stream.Send(req); err != nil {
  261. // TODO: Handle error.
  262. }
  263. }
  264. stream.CloseSend()
  265. }()
  266. for {
  267. resp, err := stream.Recv()
  268. if err == io.EOF {
  269. break
  270. }
  271. if err != nil {
  272. // TODO: handle error.
  273. }
  274. // TODO: Use resp.
  275. _ = resp
  276. }
  277. }
  278. func ExampleClient_ListCollectionIds() {
  279. ctx := context.Background()
  280. c, err := firestore.NewClient(ctx)
  281. if err != nil {
  282. // TODO: Handle error.
  283. }
  284. req := &firestorepb.ListCollectionIdsRequest{
  285. // TODO: Fill request struct fields.
  286. }
  287. it := c.ListCollectionIds(ctx, req)
  288. for {
  289. resp, err := it.Next()
  290. if err == iterator.Done {
  291. break
  292. }
  293. if err != nil {
  294. // TODO: Handle error.
  295. }
  296. // TODO: Use resp.
  297. _ = resp
  298. }
  299. }