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