Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

596 righe
24 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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package pubsub
  16. import (
  17. "math"
  18. "time"
  19. "cloud.google.com/go/iam"
  20. "cloud.google.com/go/internal/version"
  21. gax "github.com/googleapis/gax-go"
  22. "golang.org/x/net/context"
  23. "google.golang.org/api/iterator"
  24. "google.golang.org/api/option"
  25. "google.golang.org/api/transport"
  26. pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1"
  27. "google.golang.org/grpc"
  28. "google.golang.org/grpc/codes"
  29. "google.golang.org/grpc/metadata"
  30. )
  31. // SubscriberCallOptions contains the retry settings for each method of SubscriberClient.
  32. type SubscriberCallOptions struct {
  33. CreateSubscription []gax.CallOption
  34. GetSubscription []gax.CallOption
  35. UpdateSubscription []gax.CallOption
  36. ListSubscriptions []gax.CallOption
  37. DeleteSubscription []gax.CallOption
  38. ModifyAckDeadline []gax.CallOption
  39. Acknowledge []gax.CallOption
  40. Pull []gax.CallOption
  41. StreamingPull []gax.CallOption
  42. ModifyPushConfig []gax.CallOption
  43. ListSnapshots []gax.CallOption
  44. CreateSnapshot []gax.CallOption
  45. UpdateSnapshot []gax.CallOption
  46. DeleteSnapshot []gax.CallOption
  47. Seek []gax.CallOption
  48. }
  49. func defaultSubscriberClientOptions() []option.ClientOption {
  50. return []option.ClientOption{
  51. option.WithEndpoint("pubsub.googleapis.com:443"),
  52. option.WithScopes(DefaultAuthScopes()...),
  53. }
  54. }
  55. func defaultSubscriberCallOptions() *SubscriberCallOptions {
  56. retry := map[[2]string][]gax.CallOption{
  57. {"default", "idempotent"}: {
  58. gax.WithRetry(func() gax.Retryer {
  59. return gax.OnCodes([]codes.Code{
  60. codes.DeadlineExceeded,
  61. codes.Unavailable,
  62. }, gax.Backoff{
  63. Initial: 100 * time.Millisecond,
  64. Max: 60000 * time.Millisecond,
  65. Multiplier: 1.3,
  66. })
  67. }),
  68. },
  69. {"messaging", "pull"}: {
  70. gax.WithRetry(func() gax.Retryer {
  71. return gax.OnCodes([]codes.Code{
  72. codes.Canceled,
  73. codes.DeadlineExceeded,
  74. codes.Internal,
  75. codes.ResourceExhausted,
  76. codes.Unavailable,
  77. }, gax.Backoff{
  78. Initial: 100 * time.Millisecond,
  79. Max: 60000 * time.Millisecond,
  80. Multiplier: 1.3,
  81. })
  82. }),
  83. },
  84. {"streaming_messaging", "pull"}: {
  85. gax.WithRetry(func() gax.Retryer {
  86. return gax.OnCodes([]codes.Code{
  87. codes.Canceled,
  88. codes.DeadlineExceeded,
  89. codes.Internal,
  90. codes.ResourceExhausted,
  91. codes.Unavailable,
  92. }, gax.Backoff{
  93. Initial: 100 * time.Millisecond,
  94. Max: 60000 * time.Millisecond,
  95. Multiplier: 1.3,
  96. })
  97. }),
  98. },
  99. }
  100. return &SubscriberCallOptions{
  101. CreateSubscription: retry[[2]string{"default", "idempotent"}],
  102. GetSubscription: retry[[2]string{"default", "idempotent"}],
  103. UpdateSubscription: retry[[2]string{"default", "idempotent"}],
  104. ListSubscriptions: retry[[2]string{"default", "idempotent"}],
  105. DeleteSubscription: retry[[2]string{"default", "idempotent"}],
  106. ModifyAckDeadline: retry[[2]string{"default", "non_idempotent"}],
  107. Acknowledge: retry[[2]string{"messaging", "non_idempotent"}],
  108. Pull: retry[[2]string{"messaging", "pull"}],
  109. StreamingPull: retry[[2]string{"streaming_messaging", "pull"}],
  110. ModifyPushConfig: retry[[2]string{"default", "non_idempotent"}],
  111. ListSnapshots: retry[[2]string{"default", "idempotent"}],
  112. CreateSnapshot: retry[[2]string{"default", "idempotent"}],
  113. UpdateSnapshot: retry[[2]string{"default", "idempotent"}],
  114. DeleteSnapshot: retry[[2]string{"default", "idempotent"}],
  115. Seek: retry[[2]string{"default", "non_idempotent"}],
  116. }
  117. }
  118. // SubscriberClient is a client for interacting with Google Cloud Pub/Sub API.
  119. //
  120. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  121. type SubscriberClient struct {
  122. // The connection to the service.
  123. conn *grpc.ClientConn
  124. // The gRPC API client.
  125. subscriberClient pubsubpb.SubscriberClient
  126. // The call options for this service.
  127. CallOptions *SubscriberCallOptions
  128. // The x-goog-* metadata to be sent with each request.
  129. xGoogMetadata metadata.MD
  130. }
  131. // NewSubscriberClient creates a new subscriber client.
  132. //
  133. // The service that an application uses to manipulate subscriptions and to
  134. // consume messages from a subscription via the Pull method.
  135. func NewSubscriberClient(ctx context.Context, opts ...option.ClientOption) (*SubscriberClient, error) {
  136. conn, err := transport.DialGRPC(ctx, append(defaultSubscriberClientOptions(), opts...)...)
  137. if err != nil {
  138. return nil, err
  139. }
  140. c := &SubscriberClient{
  141. conn: conn,
  142. CallOptions: defaultSubscriberCallOptions(),
  143. subscriberClient: pubsubpb.NewSubscriberClient(conn),
  144. }
  145. c.SetGoogleClientInfo()
  146. return c, nil
  147. }
  148. // Connection returns the client's connection to the API service.
  149. func (c *SubscriberClient) Connection() *grpc.ClientConn {
  150. return c.conn
  151. }
  152. // Close closes the connection to the API service. The user should invoke this when
  153. // the client is no longer required.
  154. func (c *SubscriberClient) Close() error {
  155. return c.conn.Close()
  156. }
  157. // SetGoogleClientInfo sets the name and version of the application in
  158. // the `x-goog-api-client` header passed on each request. Intended for
  159. // use by Google-written clients.
  160. func (c *SubscriberClient) SetGoogleClientInfo(keyval ...string) {
  161. kv := append([]string{"gl-go", version.Go()}, keyval...)
  162. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  163. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  164. }
  165. func (c *SubscriberClient) SubscriptionIAM(subscription *pubsubpb.Subscription) *iam.Handle {
  166. return iam.InternalNewHandle(c.Connection(), subscription.Name)
  167. }
  168. func (c *SubscriberClient) TopicIAM(topic *pubsubpb.Topic) *iam.Handle {
  169. return iam.InternalNewHandle(c.Connection(), topic.Name)
  170. }
  171. // CreateSubscription creates a subscription to a given topic.
  172. // If the subscription already exists, returns ALREADY_EXISTS.
  173. // If the corresponding topic doesn't exist, returns NOT_FOUND.
  174. //
  175. // If the name is not provided in the request, the server will assign a random
  176. // name for this subscription on the same project as the topic, conforming
  177. // to the
  178. // resource name format (at https://cloud.google.com/pubsub/docs/overview#names).
  179. // The generated name is populated in the returned Subscription object.
  180. // Note that for REST API requests, you must specify a name in the request.
  181. func (c *SubscriberClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  182. ctx = insertMetadata(ctx, c.xGoogMetadata)
  183. opts = append(c.CallOptions.CreateSubscription[0:len(c.CallOptions.CreateSubscription):len(c.CallOptions.CreateSubscription)], opts...)
  184. var resp *pubsubpb.Subscription
  185. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  186. var err error
  187. resp, err = c.subscriberClient.CreateSubscription(ctx, req, settings.GRPC...)
  188. return err
  189. }, opts...)
  190. if err != nil {
  191. return nil, err
  192. }
  193. return resp, nil
  194. }
  195. // GetSubscription gets the configuration details of a subscription.
  196. func (c *SubscriberClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  197. ctx = insertMetadata(ctx, c.xGoogMetadata)
  198. opts = append(c.CallOptions.GetSubscription[0:len(c.CallOptions.GetSubscription):len(c.CallOptions.GetSubscription)], opts...)
  199. var resp *pubsubpb.Subscription
  200. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  201. var err error
  202. resp, err = c.subscriberClient.GetSubscription(ctx, req, settings.GRPC...)
  203. return err
  204. }, opts...)
  205. if err != nil {
  206. return nil, err
  207. }
  208. return resp, nil
  209. }
  210. // UpdateSubscription updates an existing subscription. Note that certain properties of a
  211. // subscription, such as its topic, are not modifiable.
  212. // NOTE: The style guide requires body: "subscription" instead of body: "*".
  213. // Keeping the latter for internal consistency in V1, however it should be
  214. // corrected in V2. See
  215. // https://cloud.google.com/apis/design/standard_methods#update for details.
  216. func (c *SubscriberClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  217. ctx = insertMetadata(ctx, c.xGoogMetadata)
  218. opts = append(c.CallOptions.UpdateSubscription[0:len(c.CallOptions.UpdateSubscription):len(c.CallOptions.UpdateSubscription)], opts...)
  219. var resp *pubsubpb.Subscription
  220. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  221. var err error
  222. resp, err = c.subscriberClient.UpdateSubscription(ctx, req, settings.GRPC...)
  223. return err
  224. }, opts...)
  225. if err != nil {
  226. return nil, err
  227. }
  228. return resp, nil
  229. }
  230. // ListSubscriptions lists matching subscriptions.
  231. func (c *SubscriberClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
  232. ctx = insertMetadata(ctx, c.xGoogMetadata)
  233. opts = append(c.CallOptions.ListSubscriptions[0:len(c.CallOptions.ListSubscriptions):len(c.CallOptions.ListSubscriptions)], opts...)
  234. it := &SubscriptionIterator{}
  235. it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
  236. var resp *pubsubpb.ListSubscriptionsResponse
  237. req.PageToken = pageToken
  238. if pageSize > math.MaxInt32 {
  239. req.PageSize = math.MaxInt32
  240. } else {
  241. req.PageSize = int32(pageSize)
  242. }
  243. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  244. var err error
  245. resp, err = c.subscriberClient.ListSubscriptions(ctx, req, settings.GRPC...)
  246. return err
  247. }, opts...)
  248. if err != nil {
  249. return nil, "", err
  250. }
  251. return resp.Subscriptions, resp.NextPageToken, nil
  252. }
  253. fetch := func(pageSize int, pageToken string) (string, error) {
  254. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  255. if err != nil {
  256. return "", err
  257. }
  258. it.items = append(it.items, items...)
  259. return nextPageToken, nil
  260. }
  261. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  262. return it
  263. }
  264. // DeleteSubscription deletes an existing subscription. All messages retained in the subscription
  265. // are immediately dropped. Calls to Pull after deletion will return
  266. // NOT_FOUND. After a subscription is deleted, a new one may be created with
  267. // the same name, but the new one has no association with the old
  268. // subscription or its topic unless the same topic is specified.
  269. func (c *SubscriberClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
  270. ctx = insertMetadata(ctx, c.xGoogMetadata)
  271. opts = append(c.CallOptions.DeleteSubscription[0:len(c.CallOptions.DeleteSubscription):len(c.CallOptions.DeleteSubscription)], opts...)
  272. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  273. var err error
  274. _, err = c.subscriberClient.DeleteSubscription(ctx, req, settings.GRPC...)
  275. return err
  276. }, opts...)
  277. return err
  278. }
  279. // ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful
  280. // to indicate that more time is needed to process a message by the
  281. // subscriber, or to make the message available for redelivery if the
  282. // processing was interrupted. Note that this does not modify the
  283. // subscription-level ackDeadlineSeconds used for subsequent messages.
  284. func (c *SubscriberClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
  285. ctx = insertMetadata(ctx, c.xGoogMetadata)
  286. opts = append(c.CallOptions.ModifyAckDeadline[0:len(c.CallOptions.ModifyAckDeadline):len(c.CallOptions.ModifyAckDeadline)], opts...)
  287. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  288. var err error
  289. _, err = c.subscriberClient.ModifyAckDeadline(ctx, req, settings.GRPC...)
  290. return err
  291. }, opts...)
  292. return err
  293. }
  294. // Acknowledge acknowledges the messages associated with the ack_ids in the
  295. // AcknowledgeRequest. The Pub/Sub system can remove the relevant messages
  296. // from the subscription.
  297. //
  298. // Acknowledging a message whose ack deadline has expired may succeed,
  299. // but such a message may be redelivered later. Acknowledging a message more
  300. // than once will not result in an error.
  301. func (c *SubscriberClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
  302. ctx = insertMetadata(ctx, c.xGoogMetadata)
  303. opts = append(c.CallOptions.Acknowledge[0:len(c.CallOptions.Acknowledge):len(c.CallOptions.Acknowledge)], opts...)
  304. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  305. var err error
  306. _, err = c.subscriberClient.Acknowledge(ctx, req, settings.GRPC...)
  307. return err
  308. }, opts...)
  309. return err
  310. }
  311. // Pull pulls messages from the server. Returns an empty list if there are no
  312. // messages available in the backlog. The server may return UNAVAILABLE if
  313. // there are too many concurrent pull requests pending for the given
  314. // subscription.
  315. func (c *SubscriberClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
  316. ctx = insertMetadata(ctx, c.xGoogMetadata)
  317. opts = append(c.CallOptions.Pull[0:len(c.CallOptions.Pull):len(c.CallOptions.Pull)], opts...)
  318. var resp *pubsubpb.PullResponse
  319. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  320. var err error
  321. resp, err = c.subscriberClient.Pull(ctx, req, settings.GRPC...)
  322. return err
  323. }, opts...)
  324. if err != nil {
  325. return nil, err
  326. }
  327. return resp, nil
  328. }
  329. // StreamingPull (EXPERIMENTAL) StreamingPull is an experimental feature. This RPC will
  330. // respond with UNIMPLEMENTED errors unless you have been invited to test
  331. // this feature. Contact cloud-pubsub@google.com with any questions.
  332. //
  333. // Establishes a stream with the server, which sends messages down to the
  334. // client. The client streams acknowledgements and ack deadline modifications
  335. // back to the server. The server will close the stream and return the status
  336. // on any error. The server may close the stream with status OK to reassign
  337. // server-side resources, in which case, the client should re-establish the
  338. // stream. UNAVAILABLE may also be returned in the case of a transient error
  339. // (e.g., a server restart). These should also be retried by the client. Flow
  340. // control can be achieved by configuring the underlying RPC channel.
  341. func (c *SubscriberClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
  342. ctx = insertMetadata(ctx, c.xGoogMetadata)
  343. opts = append(c.CallOptions.StreamingPull[0:len(c.CallOptions.StreamingPull):len(c.CallOptions.StreamingPull)], opts...)
  344. var resp pubsubpb.Subscriber_StreamingPullClient
  345. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  346. var err error
  347. resp, err = c.subscriberClient.StreamingPull(ctx, settings.GRPC...)
  348. return err
  349. }, opts...)
  350. if err != nil {
  351. return nil, err
  352. }
  353. return resp, nil
  354. }
  355. // ModifyPushConfig modifies the PushConfig for a specified subscription.
  356. //
  357. // This may be used to change a push subscription to a pull one (signified by
  358. // an empty PushConfig) or vice versa, or change the endpoint URL and other
  359. // attributes of a push subscription. Messages will accumulate for delivery
  360. // continuously through the call regardless of changes to the PushConfig.
  361. func (c *SubscriberClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
  362. ctx = insertMetadata(ctx, c.xGoogMetadata)
  363. opts = append(c.CallOptions.ModifyPushConfig[0:len(c.CallOptions.ModifyPushConfig):len(c.CallOptions.ModifyPushConfig)], opts...)
  364. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  365. var err error
  366. _, err = c.subscriberClient.ModifyPushConfig(ctx, req, settings.GRPC...)
  367. return err
  368. }, opts...)
  369. return err
  370. }
  371. // ListSnapshots lists the existing snapshots.
  372. func (c *SubscriberClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
  373. ctx = insertMetadata(ctx, c.xGoogMetadata)
  374. opts = append(c.CallOptions.ListSnapshots[0:len(c.CallOptions.ListSnapshots):len(c.CallOptions.ListSnapshots)], opts...)
  375. it := &SnapshotIterator{}
  376. it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
  377. var resp *pubsubpb.ListSnapshotsResponse
  378. req.PageToken = pageToken
  379. if pageSize > math.MaxInt32 {
  380. req.PageSize = math.MaxInt32
  381. } else {
  382. req.PageSize = int32(pageSize)
  383. }
  384. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  385. var err error
  386. resp, err = c.subscriberClient.ListSnapshots(ctx, req, settings.GRPC...)
  387. return err
  388. }, opts...)
  389. if err != nil {
  390. return nil, "", err
  391. }
  392. return resp.Snapshots, resp.NextPageToken, nil
  393. }
  394. fetch := func(pageSize int, pageToken string) (string, error) {
  395. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  396. if err != nil {
  397. return "", err
  398. }
  399. it.items = append(it.items, items...)
  400. return nextPageToken, nil
  401. }
  402. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  403. return it
  404. }
  405. // CreateSnapshot creates a snapshot from the requested subscription.
  406. // If the snapshot already exists, returns ALREADY_EXISTS.
  407. // If the requested subscription doesn't exist, returns NOT_FOUND.
  408. //
  409. // If the name is not provided in the request, the server will assign a random
  410. // name for this snapshot on the same project as the subscription, conforming
  411. // to the
  412. // resource name format (at https://cloud.google.com/pubsub/docs/overview#names).
  413. // The generated name is populated in the returned Snapshot object.
  414. // Note that for REST API requests, you must specify a name in the request.
  415. func (c *SubscriberClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
  416. ctx = insertMetadata(ctx, c.xGoogMetadata)
  417. opts = append(c.CallOptions.CreateSnapshot[0:len(c.CallOptions.CreateSnapshot):len(c.CallOptions.CreateSnapshot)], opts...)
  418. var resp *pubsubpb.Snapshot
  419. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  420. var err error
  421. resp, err = c.subscriberClient.CreateSnapshot(ctx, req, settings.GRPC...)
  422. return err
  423. }, opts...)
  424. if err != nil {
  425. return nil, err
  426. }
  427. return resp, nil
  428. }
  429. // UpdateSnapshot updates an existing snapshot. Note that certain properties of a snapshot
  430. // are not modifiable.
  431. // NOTE: The style guide requires body: "snapshot" instead of body: "*".
  432. // Keeping the latter for internal consistency in V1, however it should be
  433. // corrected in V2. See
  434. // https://cloud.google.com/apis/design/standard_methods#update for details.
  435. func (c *SubscriberClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
  436. ctx = insertMetadata(ctx, c.xGoogMetadata)
  437. opts = append(c.CallOptions.UpdateSnapshot[0:len(c.CallOptions.UpdateSnapshot):len(c.CallOptions.UpdateSnapshot)], opts...)
  438. var resp *pubsubpb.Snapshot
  439. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  440. var err error
  441. resp, err = c.subscriberClient.UpdateSnapshot(ctx, req, settings.GRPC...)
  442. return err
  443. }, opts...)
  444. if err != nil {
  445. return nil, err
  446. }
  447. return resp, nil
  448. }
  449. // DeleteSnapshot removes an existing snapshot. All messages retained in the snapshot
  450. // are immediately dropped. After a snapshot is deleted, a new one may be
  451. // created with the same name, but the new one has no association with the old
  452. // snapshot or its subscription, unless the same subscription is specified.
  453. func (c *SubscriberClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
  454. ctx = insertMetadata(ctx, c.xGoogMetadata)
  455. opts = append(c.CallOptions.DeleteSnapshot[0:len(c.CallOptions.DeleteSnapshot):len(c.CallOptions.DeleteSnapshot)], opts...)
  456. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  457. var err error
  458. _, err = c.subscriberClient.DeleteSnapshot(ctx, req, settings.GRPC...)
  459. return err
  460. }, opts...)
  461. return err
  462. }
  463. // Seek seeks an existing subscription to a point in time or to a given snapshot,
  464. // whichever is provided in the request.
  465. func (c *SubscriberClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
  466. ctx = insertMetadata(ctx, c.xGoogMetadata)
  467. opts = append(c.CallOptions.Seek[0:len(c.CallOptions.Seek):len(c.CallOptions.Seek)], opts...)
  468. var resp *pubsubpb.SeekResponse
  469. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  470. var err error
  471. resp, err = c.subscriberClient.Seek(ctx, req, settings.GRPC...)
  472. return err
  473. }, opts...)
  474. if err != nil {
  475. return nil, err
  476. }
  477. return resp, nil
  478. }
  479. // SnapshotIterator manages a stream of *pubsubpb.Snapshot.
  480. type SnapshotIterator struct {
  481. items []*pubsubpb.Snapshot
  482. pageInfo *iterator.PageInfo
  483. nextFunc func() error
  484. // InternalFetch is for use by the Google Cloud Libraries only.
  485. // It is not part of the stable interface of this package.
  486. //
  487. // InternalFetch returns results from a single call to the underlying RPC.
  488. // The number of results is no greater than pageSize.
  489. // If there are no more results, nextPageToken is empty and err is nil.
  490. InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Snapshot, nextPageToken string, err error)
  491. }
  492. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  493. func (it *SnapshotIterator) PageInfo() *iterator.PageInfo {
  494. return it.pageInfo
  495. }
  496. // Next returns the next result. Its second return value is iterator.Done if there are no more
  497. // results. Once Next returns Done, all subsequent calls will return Done.
  498. func (it *SnapshotIterator) Next() (*pubsubpb.Snapshot, error) {
  499. var item *pubsubpb.Snapshot
  500. if err := it.nextFunc(); err != nil {
  501. return item, err
  502. }
  503. item = it.items[0]
  504. it.items = it.items[1:]
  505. return item, nil
  506. }
  507. func (it *SnapshotIterator) bufLen() int {
  508. return len(it.items)
  509. }
  510. func (it *SnapshotIterator) takeBuf() interface{} {
  511. b := it.items
  512. it.items = nil
  513. return b
  514. }
  515. // SubscriptionIterator manages a stream of *pubsubpb.Subscription.
  516. type SubscriptionIterator struct {
  517. items []*pubsubpb.Subscription
  518. pageInfo *iterator.PageInfo
  519. nextFunc func() error
  520. // InternalFetch is for use by the Google Cloud Libraries only.
  521. // It is not part of the stable interface of this package.
  522. //
  523. // InternalFetch returns results from a single call to the underlying RPC.
  524. // The number of results is no greater than pageSize.
  525. // If there are no more results, nextPageToken is empty and err is nil.
  526. InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Subscription, nextPageToken string, err error)
  527. }
  528. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  529. func (it *SubscriptionIterator) PageInfo() *iterator.PageInfo {
  530. return it.pageInfo
  531. }
  532. // Next returns the next result. Its second return value is iterator.Done if there are no more
  533. // results. Once Next returns Done, all subsequent calls will return Done.
  534. func (it *SubscriptionIterator) Next() (*pubsubpb.Subscription, error) {
  535. var item *pubsubpb.Subscription
  536. if err := it.nextFunc(); err != nil {
  537. return item, err
  538. }
  539. item = it.items[0]
  540. it.items = it.items[1:]
  541. return item, nil
  542. }
  543. func (it *SubscriptionIterator) bufLen() int {
  544. return len(it.items)
  545. }
  546. func (it *SubscriptionIterator) takeBuf() interface{} {
  547. b := it.items
  548. it.items = nil
  549. return b
  550. }