1// Copyright 2020 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 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package translate 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 "github.com/golang/protobuf/proto" 29 gax "github.com/googleapis/gax-go/v2" 30 "google.golang.org/api/iterator" 31 "google.golang.org/api/option" 32 gtransport "google.golang.org/api/transport/grpc" 33 translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" 34 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 35 "google.golang.org/grpc" 36 "google.golang.org/grpc/codes" 37 "google.golang.org/grpc/metadata" 38) 39 40var newTranslationClientHook clientHook 41 42// TranslationCallOptions contains the retry settings for each method of TranslationClient. 43type TranslationCallOptions struct { 44 TranslateText []gax.CallOption 45 DetectLanguage []gax.CallOption 46 GetSupportedLanguages []gax.CallOption 47 BatchTranslateText []gax.CallOption 48 CreateGlossary []gax.CallOption 49 ListGlossaries []gax.CallOption 50 GetGlossary []gax.CallOption 51 DeleteGlossary []gax.CallOption 52} 53 54func defaultTranslationClientOptions() []option.ClientOption { 55 return []option.ClientOption{ 56 option.WithEndpoint("translate.googleapis.com:443"), 57 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 58 option.WithScopes(DefaultAuthScopes()...), 59 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 60 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 61 } 62} 63 64func defaultTranslationCallOptions() *TranslationCallOptions { 65 return &TranslationCallOptions{ 66 TranslateText: []gax.CallOption{}, 67 DetectLanguage: []gax.CallOption{}, 68 GetSupportedLanguages: []gax.CallOption{ 69 gax.WithRetry(func() gax.Retryer { 70 return gax.OnCodes([]codes.Code{ 71 codes.DeadlineExceeded, 72 codes.Unavailable, 73 }, gax.Backoff{ 74 Initial: 100 * time.Millisecond, 75 Max: 60000 * time.Millisecond, 76 Multiplier: 1.30, 77 }) 78 }), 79 }, 80 BatchTranslateText: []gax.CallOption{}, 81 CreateGlossary: []gax.CallOption{}, 82 ListGlossaries: []gax.CallOption{ 83 gax.WithRetry(func() gax.Retryer { 84 return gax.OnCodes([]codes.Code{ 85 codes.DeadlineExceeded, 86 codes.Unavailable, 87 }, gax.Backoff{ 88 Initial: 100 * time.Millisecond, 89 Max: 60000 * time.Millisecond, 90 Multiplier: 1.30, 91 }) 92 }), 93 }, 94 GetGlossary: []gax.CallOption{ 95 gax.WithRetry(func() gax.Retryer { 96 return gax.OnCodes([]codes.Code{ 97 codes.DeadlineExceeded, 98 codes.Unavailable, 99 }, gax.Backoff{ 100 Initial: 100 * time.Millisecond, 101 Max: 60000 * time.Millisecond, 102 Multiplier: 1.30, 103 }) 104 }), 105 }, 106 DeleteGlossary: []gax.CallOption{ 107 gax.WithRetry(func() gax.Retryer { 108 return gax.OnCodes([]codes.Code{ 109 codes.DeadlineExceeded, 110 codes.Unavailable, 111 }, gax.Backoff{ 112 Initial: 100 * time.Millisecond, 113 Max: 60000 * time.Millisecond, 114 Multiplier: 1.30, 115 }) 116 }), 117 }, 118 } 119} 120 121// TranslationClient is a client for interacting with Cloud Translation API. 122// 123// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 124type TranslationClient struct { 125 // Connection pool of gRPC connections to the service. 126 connPool gtransport.ConnPool 127 128 // The gRPC API client. 129 translationClient translatepb.TranslationServiceClient 130 131 // LROClient is used internally to handle longrunning operations. 132 // It is exposed so that its CallOptions can be modified if required. 133 // Users should not Close this client. 134 LROClient *lroauto.OperationsClient 135 136 // The call options for this service. 137 CallOptions *TranslationCallOptions 138 139 // The x-goog-* metadata to be sent with each request. 140 xGoogMetadata metadata.MD 141} 142 143// NewTranslationClient creates a new translation service client. 144// 145// Provides natural language translation operations. 146func NewTranslationClient(ctx context.Context, opts ...option.ClientOption) (*TranslationClient, error) { 147 clientOpts := defaultTranslationClientOptions() 148 149 if newTranslationClientHook != nil { 150 hookOpts, err := newTranslationClientHook(ctx, clientHookParams{}) 151 if err != nil { 152 return nil, err 153 } 154 clientOpts = append(clientOpts, hookOpts...) 155 } 156 157 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 158 if err != nil { 159 return nil, err 160 } 161 c := &TranslationClient{ 162 connPool: connPool, 163 CallOptions: defaultTranslationCallOptions(), 164 165 translationClient: translatepb.NewTranslationServiceClient(connPool), 166 } 167 c.setGoogleClientInfo() 168 169 c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 170 if err != nil { 171 // This error "should not happen", since we are just reusing old connection pool 172 // and never actually need to dial. 173 // If this does happen, we could leak connp. However, we cannot close conn: 174 // If the user invoked the constructor with option.WithGRPCConn, 175 // we would close a connection that's still in use. 176 // TODO: investigate error conditions. 177 return nil, err 178 } 179 return c, nil 180} 181 182// Connection returns a connection to the API service. 183// 184// Deprecated. 185func (c *TranslationClient) Connection() *grpc.ClientConn { 186 return c.connPool.Conn() 187} 188 189// Close closes the connection to the API service. The user should invoke this when 190// the client is no longer required. 191func (c *TranslationClient) Close() error { 192 return c.connPool.Close() 193} 194 195// setGoogleClientInfo sets the name and version of the application in 196// the `x-goog-api-client` header passed on each request. Intended for 197// use by Google-written clients. 198func (c *TranslationClient) setGoogleClientInfo(keyval ...string) { 199 kv := append([]string{"gl-go", versionGo()}, keyval...) 200 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 201 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 202} 203 204// TranslateText translates input text and returns translated text. 205func (c *TranslationClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, opts ...gax.CallOption) (*translatepb.TranslateTextResponse, error) { 206 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 207 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 208 opts = append(c.CallOptions.TranslateText[0:len(c.CallOptions.TranslateText):len(c.CallOptions.TranslateText)], opts...) 209 var resp *translatepb.TranslateTextResponse 210 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 211 var err error 212 resp, err = c.translationClient.TranslateText(ctx, req, settings.GRPC...) 213 return err 214 }, opts...) 215 if err != nil { 216 return nil, err 217 } 218 return resp, nil 219} 220 221// DetectLanguage detects the language of text within a request. 222func (c *TranslationClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, opts ...gax.CallOption) (*translatepb.DetectLanguageResponse, error) { 223 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 224 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 225 opts = append(c.CallOptions.DetectLanguage[0:len(c.CallOptions.DetectLanguage):len(c.CallOptions.DetectLanguage)], opts...) 226 var resp *translatepb.DetectLanguageResponse 227 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 228 var err error 229 resp, err = c.translationClient.DetectLanguage(ctx, req, settings.GRPC...) 230 return err 231 }, opts...) 232 if err != nil { 233 return nil, err 234 } 235 return resp, nil 236} 237 238// GetSupportedLanguages returns a list of supported languages for translation. 239func (c *TranslationClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, opts ...gax.CallOption) (*translatepb.SupportedLanguages, error) { 240 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 241 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 242 opts = append(c.CallOptions.GetSupportedLanguages[0:len(c.CallOptions.GetSupportedLanguages):len(c.CallOptions.GetSupportedLanguages)], opts...) 243 var resp *translatepb.SupportedLanguages 244 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 245 var err error 246 resp, err = c.translationClient.GetSupportedLanguages(ctx, req, settings.GRPC...) 247 return err 248 }, opts...) 249 if err != nil { 250 return nil, err 251 } 252 return resp, nil 253} 254 255// BatchTranslateText translates a large volume of text in asynchronous batch mode. 256// This function provides real-time output as the inputs are being processed. 257// If caller cancels a request, the partial results (for an input file, it’s 258// all or nothing) may still be available on the specified output location. 259// 260// This call returns immediately and you can 261// use google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call. 262func (c *TranslationClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, opts ...gax.CallOption) (*BatchTranslateTextOperation, error) { 263 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 264 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 265 opts = append(c.CallOptions.BatchTranslateText[0:len(c.CallOptions.BatchTranslateText):len(c.CallOptions.BatchTranslateText)], opts...) 266 var resp *longrunningpb.Operation 267 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 268 var err error 269 resp, err = c.translationClient.BatchTranslateText(ctx, req, settings.GRPC...) 270 return err 271 }, opts...) 272 if err != nil { 273 return nil, err 274 } 275 return &BatchTranslateTextOperation{ 276 lro: longrunning.InternalNewOperation(c.LROClient, resp), 277 }, nil 278} 279 280// CreateGlossary creates a glossary and returns the long-running operation. Returns 281// NOT_FOUND, if the project doesn’t exist. 282func (c *TranslationClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, opts ...gax.CallOption) (*CreateGlossaryOperation, error) { 283 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 284 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 285 opts = append(c.CallOptions.CreateGlossary[0:len(c.CallOptions.CreateGlossary):len(c.CallOptions.CreateGlossary)], opts...) 286 var resp *longrunningpb.Operation 287 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 288 var err error 289 resp, err = c.translationClient.CreateGlossary(ctx, req, settings.GRPC...) 290 return err 291 }, opts...) 292 if err != nil { 293 return nil, err 294 } 295 return &CreateGlossaryOperation{ 296 lro: longrunning.InternalNewOperation(c.LROClient, resp), 297 }, nil 298} 299 300// ListGlossaries lists glossaries in a project. Returns NOT_FOUND, if the project doesn’t 301// exist. 302func (c *TranslationClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, opts ...gax.CallOption) *GlossaryIterator { 303 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 304 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 305 opts = append(c.CallOptions.ListGlossaries[0:len(c.CallOptions.ListGlossaries):len(c.CallOptions.ListGlossaries)], opts...) 306 it := &GlossaryIterator{} 307 req = proto.Clone(req).(*translatepb.ListGlossariesRequest) 308 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Glossary, string, error) { 309 var resp *translatepb.ListGlossariesResponse 310 req.PageToken = pageToken 311 if pageSize > math.MaxInt32 { 312 req.PageSize = math.MaxInt32 313 } else { 314 req.PageSize = int32(pageSize) 315 } 316 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 317 var err error 318 resp, err = c.translationClient.ListGlossaries(ctx, req, settings.GRPC...) 319 return err 320 }, opts...) 321 if err != nil { 322 return nil, "", err 323 } 324 325 it.Response = resp 326 return resp.Glossaries, resp.NextPageToken, nil 327 } 328 fetch := func(pageSize int, pageToken string) (string, error) { 329 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 330 if err != nil { 331 return "", err 332 } 333 it.items = append(it.items, items...) 334 return nextPageToken, nil 335 } 336 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 337 it.pageInfo.MaxSize = int(req.PageSize) 338 it.pageInfo.Token = req.PageToken 339 return it 340} 341 342// GetGlossary gets a glossary. Returns NOT_FOUND, if the glossary doesn’t 343// exist. 344func (c *TranslationClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, opts ...gax.CallOption) (*translatepb.Glossary, error) { 345 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 346 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 347 opts = append(c.CallOptions.GetGlossary[0:len(c.CallOptions.GetGlossary):len(c.CallOptions.GetGlossary)], opts...) 348 var resp *translatepb.Glossary 349 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 350 var err error 351 resp, err = c.translationClient.GetGlossary(ctx, req, settings.GRPC...) 352 return err 353 }, opts...) 354 if err != nil { 355 return nil, err 356 } 357 return resp, nil 358} 359 360// DeleteGlossary deletes a glossary, or cancels glossary construction 361// if the glossary isn’t created yet. 362// Returns NOT_FOUND, if the glossary doesn’t exist. 363func (c *TranslationClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, opts ...gax.CallOption) (*DeleteGlossaryOperation, error) { 364 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 365 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 366 opts = append(c.CallOptions.DeleteGlossary[0:len(c.CallOptions.DeleteGlossary):len(c.CallOptions.DeleteGlossary)], opts...) 367 var resp *longrunningpb.Operation 368 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 369 var err error 370 resp, err = c.translationClient.DeleteGlossary(ctx, req, settings.GRPC...) 371 return err 372 }, opts...) 373 if err != nil { 374 return nil, err 375 } 376 return &DeleteGlossaryOperation{ 377 lro: longrunning.InternalNewOperation(c.LROClient, resp), 378 }, nil 379} 380 381// BatchTranslateTextOperation manages a long-running operation from BatchTranslateText. 382type BatchTranslateTextOperation struct { 383 lro *longrunning.Operation 384} 385 386// BatchTranslateTextOperation returns a new BatchTranslateTextOperation from a given name. 387// The name must be that of a previously created BatchTranslateTextOperation, possibly from a different process. 388func (c *TranslationClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation { 389 return &BatchTranslateTextOperation{ 390 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 391 } 392} 393 394// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 395// 396// See documentation of Poll for error-handling information. 397func (op *BatchTranslateTextOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error) { 398 var resp translatepb.BatchTranslateResponse 399 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 400 return nil, err 401 } 402 return &resp, nil 403} 404 405// Poll fetches the latest state of the long-running operation. 406// 407// Poll also fetches the latest metadata, which can be retrieved by Metadata. 408// 409// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 410// the operation has completed with failure, the error is returned and op.Done will return true. 411// If Poll succeeds and the operation has completed successfully, 412// op.Done will return true, and the response of the operation is returned. 413// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 414func (op *BatchTranslateTextOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error) { 415 var resp translatepb.BatchTranslateResponse 416 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 417 return nil, err 418 } 419 if !op.Done() { 420 return nil, nil 421 } 422 return &resp, nil 423} 424 425// Metadata returns metadata associated with the long-running operation. 426// Metadata itself does not contact the server, but Poll does. 427// To get the latest metadata, call this method after a successful call to Poll. 428// If the metadata is not available, the returned metadata and error are both nil. 429func (op *BatchTranslateTextOperation) Metadata() (*translatepb.BatchTranslateMetadata, error) { 430 var meta translatepb.BatchTranslateMetadata 431 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 432 return nil, nil 433 } else if err != nil { 434 return nil, err 435 } 436 return &meta, nil 437} 438 439// Done reports whether the long-running operation has completed. 440func (op *BatchTranslateTextOperation) Done() bool { 441 return op.lro.Done() 442} 443 444// Name returns the name of the long-running operation. 445// The name is assigned by the server and is unique within the service from which the operation is created. 446func (op *BatchTranslateTextOperation) Name() string { 447 return op.lro.Name() 448} 449 450// CreateGlossaryOperation manages a long-running operation from CreateGlossary. 451type CreateGlossaryOperation struct { 452 lro *longrunning.Operation 453} 454 455// CreateGlossaryOperation returns a new CreateGlossaryOperation from a given name. 456// The name must be that of a previously created CreateGlossaryOperation, possibly from a different process. 457func (c *TranslationClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation { 458 return &CreateGlossaryOperation{ 459 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 460 } 461} 462 463// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 464// 465// See documentation of Poll for error-handling information. 466func (op *CreateGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error) { 467 var resp translatepb.Glossary 468 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 469 return nil, err 470 } 471 return &resp, nil 472} 473 474// Poll fetches the latest state of the long-running operation. 475// 476// Poll also fetches the latest metadata, which can be retrieved by Metadata. 477// 478// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 479// the operation has completed with failure, the error is returned and op.Done will return true. 480// If Poll succeeds and the operation has completed successfully, 481// op.Done will return true, and the response of the operation is returned. 482// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 483func (op *CreateGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error) { 484 var resp translatepb.Glossary 485 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 486 return nil, err 487 } 488 if !op.Done() { 489 return nil, nil 490 } 491 return &resp, nil 492} 493 494// Metadata returns metadata associated with the long-running operation. 495// Metadata itself does not contact the server, but Poll does. 496// To get the latest metadata, call this method after a successful call to Poll. 497// If the metadata is not available, the returned metadata and error are both nil. 498func (op *CreateGlossaryOperation) Metadata() (*translatepb.CreateGlossaryMetadata, error) { 499 var meta translatepb.CreateGlossaryMetadata 500 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 501 return nil, nil 502 } else if err != nil { 503 return nil, err 504 } 505 return &meta, nil 506} 507 508// Done reports whether the long-running operation has completed. 509func (op *CreateGlossaryOperation) Done() bool { 510 return op.lro.Done() 511} 512 513// Name returns the name of the long-running operation. 514// The name is assigned by the server and is unique within the service from which the operation is created. 515func (op *CreateGlossaryOperation) Name() string { 516 return op.lro.Name() 517} 518 519// DeleteGlossaryOperation manages a long-running operation from DeleteGlossary. 520type DeleteGlossaryOperation struct { 521 lro *longrunning.Operation 522} 523 524// DeleteGlossaryOperation returns a new DeleteGlossaryOperation from a given name. 525// The name must be that of a previously created DeleteGlossaryOperation, possibly from a different process. 526func (c *TranslationClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation { 527 return &DeleteGlossaryOperation{ 528 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 529 } 530} 531 532// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 533// 534// See documentation of Poll for error-handling information. 535func (op *DeleteGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error) { 536 var resp translatepb.DeleteGlossaryResponse 537 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 538 return nil, err 539 } 540 return &resp, nil 541} 542 543// Poll fetches the latest state of the long-running operation. 544// 545// Poll also fetches the latest metadata, which can be retrieved by Metadata. 546// 547// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 548// the operation has completed with failure, the error is returned and op.Done will return true. 549// If Poll succeeds and the operation has completed successfully, 550// op.Done will return true, and the response of the operation is returned. 551// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 552func (op *DeleteGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error) { 553 var resp translatepb.DeleteGlossaryResponse 554 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 555 return nil, err 556 } 557 if !op.Done() { 558 return nil, nil 559 } 560 return &resp, nil 561} 562 563// Metadata returns metadata associated with the long-running operation. 564// Metadata itself does not contact the server, but Poll does. 565// To get the latest metadata, call this method after a successful call to Poll. 566// If the metadata is not available, the returned metadata and error are both nil. 567func (op *DeleteGlossaryOperation) Metadata() (*translatepb.DeleteGlossaryMetadata, error) { 568 var meta translatepb.DeleteGlossaryMetadata 569 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 570 return nil, nil 571 } else if err != nil { 572 return nil, err 573 } 574 return &meta, nil 575} 576 577// Done reports whether the long-running operation has completed. 578func (op *DeleteGlossaryOperation) Done() bool { 579 return op.lro.Done() 580} 581 582// Name returns the name of the long-running operation. 583// The name is assigned by the server and is unique within the service from which the operation is created. 584func (op *DeleteGlossaryOperation) Name() string { 585 return op.lro.Name() 586} 587 588// GlossaryIterator manages a stream of *translatepb.Glossary. 589type GlossaryIterator struct { 590 items []*translatepb.Glossary 591 pageInfo *iterator.PageInfo 592 nextFunc func() error 593 594 // Response is the raw response for the current page. 595 // It must be cast to the RPC response type. 596 // Calling Next() or InternalFetch() updates this value. 597 Response interface{} 598 599 // InternalFetch is for use by the Google Cloud Libraries only. 600 // It is not part of the stable interface of this package. 601 // 602 // InternalFetch returns results from a single call to the underlying RPC. 603 // The number of results is no greater than pageSize. 604 // If there are no more results, nextPageToken is empty and err is nil. 605 InternalFetch func(pageSize int, pageToken string) (results []*translatepb.Glossary, nextPageToken string, err error) 606} 607 608// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 609func (it *GlossaryIterator) PageInfo() *iterator.PageInfo { 610 return it.pageInfo 611} 612 613// Next returns the next result. Its second return value is iterator.Done if there are no more 614// results. Once Next returns Done, all subsequent calls will return Done. 615func (it *GlossaryIterator) Next() (*translatepb.Glossary, error) { 616 var item *translatepb.Glossary 617 if err := it.nextFunc(); err != nil { 618 return item, err 619 } 620 item = it.items[0] 621 it.items = it.items[1:] 622 return item, nil 623} 624 625func (it *GlossaryIterator) bufLen() int { 626 return len(it.items) 627} 628 629func (it *GlossaryIterator) takeBuf() interface{} { 630 b := it.items 631 it.items = nil 632 return b 633} 634