您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

325 行
6.6 KiB

  1. // Copyright 2019 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 pubsub_test
  16. import (
  17. "context"
  18. "io"
  19. pubsub "cloud.google.com/go/pubsub/apiv1"
  20. "google.golang.org/api/iterator"
  21. pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1"
  22. )
  23. func ExampleNewSubscriberClient() {
  24. ctx := context.Background()
  25. c, err := pubsub.NewSubscriberClient(ctx)
  26. if err != nil {
  27. // TODO: Handle error.
  28. }
  29. // TODO: Use client.
  30. _ = c
  31. }
  32. func ExampleSubscriberClient_CreateSubscription() {
  33. ctx := context.Background()
  34. c, err := pubsub.NewSubscriberClient(ctx)
  35. if err != nil {
  36. // TODO: Handle error.
  37. }
  38. req := &pubsubpb.Subscription{
  39. // TODO: Fill request struct fields.
  40. }
  41. resp, err := c.CreateSubscription(ctx, req)
  42. if err != nil {
  43. // TODO: Handle error.
  44. }
  45. // TODO: Use resp.
  46. _ = resp
  47. }
  48. func ExampleSubscriberClient_GetSubscription() {
  49. ctx := context.Background()
  50. c, err := pubsub.NewSubscriberClient(ctx)
  51. if err != nil {
  52. // TODO: Handle error.
  53. }
  54. req := &pubsubpb.GetSubscriptionRequest{
  55. // TODO: Fill request struct fields.
  56. }
  57. resp, err := c.GetSubscription(ctx, req)
  58. if err != nil {
  59. // TODO: Handle error.
  60. }
  61. // TODO: Use resp.
  62. _ = resp
  63. }
  64. func ExampleSubscriberClient_UpdateSubscription() {
  65. ctx := context.Background()
  66. c, err := pubsub.NewSubscriberClient(ctx)
  67. if err != nil {
  68. // TODO: Handle error.
  69. }
  70. req := &pubsubpb.UpdateSubscriptionRequest{
  71. // TODO: Fill request struct fields.
  72. }
  73. resp, err := c.UpdateSubscription(ctx, req)
  74. if err != nil {
  75. // TODO: Handle error.
  76. }
  77. // TODO: Use resp.
  78. _ = resp
  79. }
  80. func ExampleSubscriberClient_ListSubscriptions() {
  81. ctx := context.Background()
  82. c, err := pubsub.NewSubscriberClient(ctx)
  83. if err != nil {
  84. // TODO: Handle error.
  85. }
  86. req := &pubsubpb.ListSubscriptionsRequest{
  87. // TODO: Fill request struct fields.
  88. }
  89. it := c.ListSubscriptions(ctx, req)
  90. for {
  91. resp, err := it.Next()
  92. if err == iterator.Done {
  93. break
  94. }
  95. if err != nil {
  96. // TODO: Handle error.
  97. }
  98. // TODO: Use resp.
  99. _ = resp
  100. }
  101. }
  102. func ExampleSubscriberClient_DeleteSubscription() {
  103. ctx := context.Background()
  104. c, err := pubsub.NewSubscriberClient(ctx)
  105. if err != nil {
  106. // TODO: Handle error.
  107. }
  108. req := &pubsubpb.DeleteSubscriptionRequest{
  109. // TODO: Fill request struct fields.
  110. }
  111. err = c.DeleteSubscription(ctx, req)
  112. if err != nil {
  113. // TODO: Handle error.
  114. }
  115. }
  116. func ExampleSubscriberClient_ModifyAckDeadline() {
  117. ctx := context.Background()
  118. c, err := pubsub.NewSubscriberClient(ctx)
  119. if err != nil {
  120. // TODO: Handle error.
  121. }
  122. req := &pubsubpb.ModifyAckDeadlineRequest{
  123. // TODO: Fill request struct fields.
  124. }
  125. err = c.ModifyAckDeadline(ctx, req)
  126. if err != nil {
  127. // TODO: Handle error.
  128. }
  129. }
  130. func ExampleSubscriberClient_Acknowledge() {
  131. ctx := context.Background()
  132. c, err := pubsub.NewSubscriberClient(ctx)
  133. if err != nil {
  134. // TODO: Handle error.
  135. }
  136. req := &pubsubpb.AcknowledgeRequest{
  137. // TODO: Fill request struct fields.
  138. }
  139. err = c.Acknowledge(ctx, req)
  140. if err != nil {
  141. // TODO: Handle error.
  142. }
  143. }
  144. func ExampleSubscriberClient_Pull() {
  145. ctx := context.Background()
  146. c, err := pubsub.NewSubscriberClient(ctx)
  147. if err != nil {
  148. // TODO: Handle error.
  149. }
  150. req := &pubsubpb.PullRequest{
  151. // TODO: Fill request struct fields.
  152. }
  153. resp, err := c.Pull(ctx, req)
  154. if err != nil {
  155. // TODO: Handle error.
  156. }
  157. // TODO: Use resp.
  158. _ = resp
  159. }
  160. func ExampleSubscriberClient_StreamingPull() {
  161. ctx := context.Background()
  162. c, err := pubsub.NewSubscriberClient(ctx)
  163. if err != nil {
  164. // TODO: Handle error.
  165. }
  166. stream, err := c.StreamingPull(ctx)
  167. if err != nil {
  168. // TODO: Handle error.
  169. }
  170. go func() {
  171. reqs := []*pubsubpb.StreamingPullRequest{
  172. // TODO: Create requests.
  173. }
  174. for _, req := range reqs {
  175. if err := stream.Send(req); err != nil {
  176. // TODO: Handle error.
  177. }
  178. }
  179. stream.CloseSend()
  180. }()
  181. for {
  182. resp, err := stream.Recv()
  183. if err == io.EOF {
  184. break
  185. }
  186. if err != nil {
  187. // TODO: handle error.
  188. }
  189. // TODO: Use resp.
  190. _ = resp
  191. }
  192. }
  193. func ExampleSubscriberClient_ModifyPushConfig() {
  194. ctx := context.Background()
  195. c, err := pubsub.NewSubscriberClient(ctx)
  196. if err != nil {
  197. // TODO: Handle error.
  198. }
  199. req := &pubsubpb.ModifyPushConfigRequest{
  200. // TODO: Fill request struct fields.
  201. }
  202. err = c.ModifyPushConfig(ctx, req)
  203. if err != nil {
  204. // TODO: Handle error.
  205. }
  206. }
  207. func ExampleSubscriberClient_ListSnapshots() {
  208. ctx := context.Background()
  209. c, err := pubsub.NewSubscriberClient(ctx)
  210. if err != nil {
  211. // TODO: Handle error.
  212. }
  213. req := &pubsubpb.ListSnapshotsRequest{
  214. // TODO: Fill request struct fields.
  215. }
  216. it := c.ListSnapshots(ctx, req)
  217. for {
  218. resp, err := it.Next()
  219. if err == iterator.Done {
  220. break
  221. }
  222. if err != nil {
  223. // TODO: Handle error.
  224. }
  225. // TODO: Use resp.
  226. _ = resp
  227. }
  228. }
  229. func ExampleSubscriberClient_CreateSnapshot() {
  230. ctx := context.Background()
  231. c, err := pubsub.NewSubscriberClient(ctx)
  232. if err != nil {
  233. // TODO: Handle error.
  234. }
  235. req := &pubsubpb.CreateSnapshotRequest{
  236. // TODO: Fill request struct fields.
  237. }
  238. resp, err := c.CreateSnapshot(ctx, req)
  239. if err != nil {
  240. // TODO: Handle error.
  241. }
  242. // TODO: Use resp.
  243. _ = resp
  244. }
  245. func ExampleSubscriberClient_UpdateSnapshot() {
  246. ctx := context.Background()
  247. c, err := pubsub.NewSubscriberClient(ctx)
  248. if err != nil {
  249. // TODO: Handle error.
  250. }
  251. req := &pubsubpb.UpdateSnapshotRequest{
  252. // TODO: Fill request struct fields.
  253. }
  254. resp, err := c.UpdateSnapshot(ctx, req)
  255. if err != nil {
  256. // TODO: Handle error.
  257. }
  258. // TODO: Use resp.
  259. _ = resp
  260. }
  261. func ExampleSubscriberClient_DeleteSnapshot() {
  262. ctx := context.Background()
  263. c, err := pubsub.NewSubscriberClient(ctx)
  264. if err != nil {
  265. // TODO: Handle error.
  266. }
  267. req := &pubsubpb.DeleteSnapshotRequest{
  268. // TODO: Fill request struct fields.
  269. }
  270. err = c.DeleteSnapshot(ctx, req)
  271. if err != nil {
  272. // TODO: Handle error.
  273. }
  274. }
  275. func ExampleSubscriberClient_Seek() {
  276. ctx := context.Background()
  277. c, err := pubsub.NewSubscriberClient(ctx)
  278. if err != nil {
  279. // TODO: Handle error.
  280. }
  281. req := &pubsubpb.SeekRequest{
  282. // TODO: Fill request struct fields.
  283. }
  284. resp, err := c.Seek(ctx, req)
  285. if err != nil {
  286. // TODO: Handle error.
  287. }
  288. // TODO: Use resp.
  289. _ = resp
  290. }