Debian Codegraph @

translate/apiv3/translation_client.go

raw
1 // Copyright 2025 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
17 package translate
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 "cloud.google.com/go/longrunning"
30 lroauto "cloud.google.com/go/longrunning/autogen"
31 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
32 translatepb "cloud.google.com/go/translate/apiv3/translatepb"
33 gax "github.com/googleapis/gax-go/v2"
34 "google.golang.org/api/iterator"
35 "google.golang.org/api/option"
36 "google.golang.org/api/option/internaloption"
37 gtransport "google.golang.org/api/transport/grpc"
38 httptransport "google.golang.org/api/transport/http"
39 locationpb "google.golang.org/genproto/googleapis/cloud/location"
40 "google.golang.org/grpc"
41 "google.golang.org/grpc/codes"
42 "google.golang.org/protobuf/encoding/protojson"
43 "google.golang.org/protobuf/proto"
44 )
45
46 var newTranslationClientHook clientHook
47
48 // TranslationCallOptions contains the retry settings for each method of TranslationClient.
49 type TranslationCallOptions struct {
50 TranslateText []gax.CallOption
51 RomanizeText []gax.CallOption
52 DetectLanguage []gax.CallOption
53 GetSupportedLanguages []gax.CallOption
54 TranslateDocument []gax.CallOption
55 BatchTranslateText []gax.CallOption
56 BatchTranslateDocument []gax.CallOption
57 CreateGlossary []gax.CallOption
58 UpdateGlossary []gax.CallOption
59 ListGlossaries []gax.CallOption
60 GetGlossary []gax.CallOption
61 DeleteGlossary []gax.CallOption
62 GetGlossaryEntry []gax.CallOption
63 ListGlossaryEntries []gax.CallOption
64 CreateGlossaryEntry []gax.CallOption
65 UpdateGlossaryEntry []gax.CallOption
66 DeleteGlossaryEntry []gax.CallOption
67 CreateDataset []gax.CallOption
68 GetDataset []gax.CallOption
69 ListDatasets []gax.CallOption
70 DeleteDataset []gax.CallOption
71 CreateAdaptiveMtDataset []gax.CallOption
72 DeleteAdaptiveMtDataset []gax.CallOption
73 GetAdaptiveMtDataset []gax.CallOption
74 ListAdaptiveMtDatasets []gax.CallOption
75 AdaptiveMtTranslate []gax.CallOption
76 GetAdaptiveMtFile []gax.CallOption
77 DeleteAdaptiveMtFile []gax.CallOption
78 ImportAdaptiveMtFile []gax.CallOption
79 ListAdaptiveMtFiles []gax.CallOption
80 ListAdaptiveMtSentences []gax.CallOption
81 ImportData []gax.CallOption
82 ExportData []gax.CallOption
83 ListExamples []gax.CallOption
84 CreateModel []gax.CallOption
85 ListModels []gax.CallOption
86 GetModel []gax.CallOption
87 DeleteModel []gax.CallOption
88 GetLocation []gax.CallOption
89 ListLocations []gax.CallOption
90 CancelOperation []gax.CallOption
91 DeleteOperation []gax.CallOption
92 GetOperation []gax.CallOption
93 ListOperations []gax.CallOption
94 WaitOperation []gax.CallOption
95 }
96
97 func defaultTranslationGRPCClientOptions() []option.ClientOption {
98 return []option.ClientOption{
99 internaloption.WithDefaultEndpoint("translate.googleapis.com:443"),
100 internaloption.WithDefaultEndpointTemplate("translate.UNIVERSE_DOMAIN:443"),
101 internaloption.WithDefaultMTLSEndpoint("translate.mtls.googleapis.com:443"),
102 internaloption.WithDefaultUniverseDomain("googleapis.com"),
103 internaloption.WithDefaultAudience("https://translate.googleapis.com/"),
104 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
105 internaloption.EnableJwtWithScope(),
106 internaloption.EnableNewAuthLibrary(),
107 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
108 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
109 }
110 }
111
112 func defaultTranslationCallOptions() *TranslationCallOptions {
113 return &TranslationCallOptions{
114 TranslateText: []gax.CallOption{
115 gax.WithTimeout(600000 * time.Millisecond),
116 },
117 RomanizeText: []gax.CallOption{},
118 DetectLanguage: []gax.CallOption{
119 gax.WithTimeout(600000 * time.Millisecond),
120 },
121 GetSupportedLanguages: []gax.CallOption{
122 gax.WithTimeout(600000 * time.Millisecond),
123 gax.WithRetry(func() gax.Retryer {
124 return gax.OnCodes([]codes.Code{
125 codes.DeadlineExceeded,
126 codes.Unavailable,
127 }, gax.Backoff{
128 Initial: 100 * time.Millisecond,
129 Max: 60000 * time.Millisecond,
130 Multiplier: 1.30,
131 })
132 }),
133 },
134 TranslateDocument: []gax.CallOption{
135 gax.WithTimeout(600000 * time.Millisecond),
136 },
137 BatchTranslateText: []gax.CallOption{
138 gax.WithTimeout(600000 * time.Millisecond),
139 },
140 BatchTranslateDocument: []gax.CallOption{
141 gax.WithTimeout(600000 * time.Millisecond),
142 },
143 CreateGlossary: []gax.CallOption{
144 gax.WithTimeout(600000 * time.Millisecond),
145 },
146 UpdateGlossary: []gax.CallOption{},
147 ListGlossaries: []gax.CallOption{
148 gax.WithTimeout(600000 * time.Millisecond),
149 gax.WithRetry(func() gax.Retryer {
150 return gax.OnCodes([]codes.Code{
151 codes.DeadlineExceeded,
152 codes.Unavailable,
153 }, gax.Backoff{
154 Initial: 100 * time.Millisecond,
155 Max: 60000 * time.Millisecond,
156 Multiplier: 1.30,
157 })
158 }),
159 },
160 GetGlossary: []gax.CallOption{
161 gax.WithTimeout(600000 * time.Millisecond),
162 gax.WithRetry(func() gax.Retryer {
163 return gax.OnCodes([]codes.Code{
164 codes.DeadlineExceeded,
165 codes.Unavailable,
166 }, gax.Backoff{
167 Initial: 100 * time.Millisecond,
168 Max: 60000 * time.Millisecond,
169 Multiplier: 1.30,
170 })
171 }),
172 },
173 DeleteGlossary: []gax.CallOption{
174 gax.WithTimeout(600000 * time.Millisecond),
175 gax.WithRetry(func() gax.Retryer {
176 return gax.OnCodes([]codes.Code{
177 codes.DeadlineExceeded,
178 codes.Unavailable,
179 }, gax.Backoff{
180 Initial: 100 * time.Millisecond,
181 Max: 60000 * time.Millisecond,
182 Multiplier: 1.30,
183 })
184 }),
185 },
186 GetGlossaryEntry: []gax.CallOption{},
187 ListGlossaryEntries: []gax.CallOption{},
188 CreateGlossaryEntry: []gax.CallOption{},
189 UpdateGlossaryEntry: []gax.CallOption{},
190 DeleteGlossaryEntry: []gax.CallOption{},
191 CreateDataset: []gax.CallOption{},
192 GetDataset: []gax.CallOption{},
193 ListDatasets: []gax.CallOption{},
194 DeleteDataset: []gax.CallOption{},
195 CreateAdaptiveMtDataset: []gax.CallOption{},
196 DeleteAdaptiveMtDataset: []gax.CallOption{},
197 GetAdaptiveMtDataset: []gax.CallOption{},
198 ListAdaptiveMtDatasets: []gax.CallOption{},
199 AdaptiveMtTranslate: []gax.CallOption{},
200 GetAdaptiveMtFile: []gax.CallOption{},
201 DeleteAdaptiveMtFile: []gax.CallOption{},
202 ImportAdaptiveMtFile: []gax.CallOption{},
203 ListAdaptiveMtFiles: []gax.CallOption{},
204 ListAdaptiveMtSentences: []gax.CallOption{},
205 ImportData: []gax.CallOption{},
206 ExportData: []gax.CallOption{},
207 ListExamples: []gax.CallOption{},
208 CreateModel: []gax.CallOption{},
209 ListModels: []gax.CallOption{},
210 GetModel: []gax.CallOption{},
211 DeleteModel: []gax.CallOption{},
212 GetLocation: []gax.CallOption{},
213 ListLocations: []gax.CallOption{},
214 CancelOperation: []gax.CallOption{},
215 DeleteOperation: []gax.CallOption{},
216 GetOperation: []gax.CallOption{},
217 ListOperations: []gax.CallOption{},
218 WaitOperation: []gax.CallOption{},
219 }
220 }
221
222 func defaultTranslationRESTCallOptions() *TranslationCallOptions {
223 return &TranslationCallOptions{
224 TranslateText: []gax.CallOption{
225 gax.WithTimeout(600000 * time.Millisecond),
226 },
227 RomanizeText: []gax.CallOption{},
228 DetectLanguage: []gax.CallOption{
229 gax.WithTimeout(600000 * time.Millisecond),
230 },
231 GetSupportedLanguages: []gax.CallOption{
232 gax.WithTimeout(600000 * time.Millisecond),
233 gax.WithRetry(func() gax.Retryer {
234 return gax.OnHTTPCodes(gax.Backoff{
235 Initial: 100 * time.Millisecond,
236 Max: 60000 * time.Millisecond,
237 Multiplier: 1.30,
238 },
239 http.StatusGatewayTimeout,
240 http.StatusServiceUnavailable)
241 }),
242 },
243 TranslateDocument: []gax.CallOption{
244 gax.WithTimeout(600000 * time.Millisecond),
245 },
246 BatchTranslateText: []gax.CallOption{
247 gax.WithTimeout(600000 * time.Millisecond),
248 },
249 BatchTranslateDocument: []gax.CallOption{
250 gax.WithTimeout(600000 * time.Millisecond),
251 },
252 CreateGlossary: []gax.CallOption{
253 gax.WithTimeout(600000 * time.Millisecond),
254 },
255 UpdateGlossary: []gax.CallOption{},
256 ListGlossaries: []gax.CallOption{
257 gax.WithTimeout(600000 * time.Millisecond),
258 gax.WithRetry(func() gax.Retryer {
259 return gax.OnHTTPCodes(gax.Backoff{
260 Initial: 100 * time.Millisecond,
261 Max: 60000 * time.Millisecond,
262 Multiplier: 1.30,
263 },
264 http.StatusGatewayTimeout,
265 http.StatusServiceUnavailable)
266 }),
267 },
268 GetGlossary: []gax.CallOption{
269 gax.WithTimeout(600000 * time.Millisecond),
270 gax.WithRetry(func() gax.Retryer {
271 return gax.OnHTTPCodes(gax.Backoff{
272 Initial: 100 * time.Millisecond,
273 Max: 60000 * time.Millisecond,
274 Multiplier: 1.30,
275 },
276 http.StatusGatewayTimeout,
277 http.StatusServiceUnavailable)
278 }),
279 },
280 DeleteGlossary: []gax.CallOption{
281 gax.WithTimeout(600000 * time.Millisecond),
282 gax.WithRetry(func() gax.Retryer {
283 return gax.OnHTTPCodes(gax.Backoff{
284 Initial: 100 * time.Millisecond,
285 Max: 60000 * time.Millisecond,
286 Multiplier: 1.30,
287 },
288 http.StatusGatewayTimeout,
289 http.StatusServiceUnavailable)
290 }),
291 },
292 GetGlossaryEntry: []gax.CallOption{},
293 ListGlossaryEntries: []gax.CallOption{},
294 CreateGlossaryEntry: []gax.CallOption{},
295 UpdateGlossaryEntry: []gax.CallOption{},
296 DeleteGlossaryEntry: []gax.CallOption{},
297 CreateDataset: []gax.CallOption{},
298 GetDataset: []gax.CallOption{},
299 ListDatasets: []gax.CallOption{},
300 DeleteDataset: []gax.CallOption{},
301 CreateAdaptiveMtDataset: []gax.CallOption{},
302 DeleteAdaptiveMtDataset: []gax.CallOption{},
303 GetAdaptiveMtDataset: []gax.CallOption{},
304 ListAdaptiveMtDatasets: []gax.CallOption{},
305 AdaptiveMtTranslate: []gax.CallOption{},
306 GetAdaptiveMtFile: []gax.CallOption{},
307 DeleteAdaptiveMtFile: []gax.CallOption{},
308 ImportAdaptiveMtFile: []gax.CallOption{},
309 ListAdaptiveMtFiles: []gax.CallOption{},
310 ListAdaptiveMtSentences: []gax.CallOption{},
311 ImportData: []gax.CallOption{},
312 ExportData: []gax.CallOption{},
313 ListExamples: []gax.CallOption{},
314 CreateModel: []gax.CallOption{},
315 ListModels: []gax.CallOption{},
316 GetModel: []gax.CallOption{},
317 DeleteModel: []gax.CallOption{},
318 GetLocation: []gax.CallOption{},
319 ListLocations: []gax.CallOption{},
320 CancelOperation: []gax.CallOption{},
321 DeleteOperation: []gax.CallOption{},
322 GetOperation: []gax.CallOption{},
323 ListOperations: []gax.CallOption{},
324 WaitOperation: []gax.CallOption{},
325 }
326 }
327
328 // internalTranslationClient is an interface that defines the methods available from Cloud Translation API.
329 type internalTranslationClient interface {
330 Close() error
331 setGoogleClientInfo(...string)
332 Connection() *grpc.ClientConn
333 TranslateText(context.Context, *translatepb.TranslateTextRequest, ...gax.CallOption) (*translatepb.TranslateTextResponse, error)
334 RomanizeText(context.Context, *translatepb.RomanizeTextRequest, ...gax.CallOption) (*translatepb.RomanizeTextResponse, error)
335 DetectLanguage(context.Context, *translatepb.DetectLanguageRequest, ...gax.CallOption) (*translatepb.DetectLanguageResponse, error)
336 GetSupportedLanguages(context.Context, *translatepb.GetSupportedLanguagesRequest, ...gax.CallOption) (*translatepb.SupportedLanguages, error)
337 TranslateDocument(context.Context, *translatepb.TranslateDocumentRequest, ...gax.CallOption) (*translatepb.TranslateDocumentResponse, error)
338 BatchTranslateText(context.Context, *translatepb.BatchTranslateTextRequest, ...gax.CallOption) (*BatchTranslateTextOperation, error)
339 BatchTranslateTextOperation(name string) *BatchTranslateTextOperation
340 BatchTranslateDocument(context.Context, *translatepb.BatchTranslateDocumentRequest, ...gax.CallOption) (*BatchTranslateDocumentOperation, error)
341 BatchTranslateDocumentOperation(name string) *BatchTranslateDocumentOperation
342 CreateGlossary(context.Context, *translatepb.CreateGlossaryRequest, ...gax.CallOption) (*CreateGlossaryOperation, error)
343 CreateGlossaryOperation(name string) *CreateGlossaryOperation
344 UpdateGlossary(context.Context, *translatepb.UpdateGlossaryRequest, ...gax.CallOption) (*UpdateGlossaryOperation, error)
345 UpdateGlossaryOperation(name string) *UpdateGlossaryOperation
346 ListGlossaries(context.Context, *translatepb.ListGlossariesRequest, ...gax.CallOption) *GlossaryIterator
347 GetGlossary(context.Context, *translatepb.GetGlossaryRequest, ...gax.CallOption) (*translatepb.Glossary, error)
348 DeleteGlossary(context.Context, *translatepb.DeleteGlossaryRequest, ...gax.CallOption) (*DeleteGlossaryOperation, error)
349 DeleteGlossaryOperation(name string) *DeleteGlossaryOperation
350 GetGlossaryEntry(context.Context, *translatepb.GetGlossaryEntryRequest, ...gax.CallOption) (*translatepb.GlossaryEntry, error)
351 ListGlossaryEntries(context.Context, *translatepb.ListGlossaryEntriesRequest, ...gax.CallOption) *GlossaryEntryIterator
352 CreateGlossaryEntry(context.Context, *translatepb.CreateGlossaryEntryRequest, ...gax.CallOption) (*translatepb.GlossaryEntry, error)
353 UpdateGlossaryEntry(context.Context, *translatepb.UpdateGlossaryEntryRequest, ...gax.CallOption) (*translatepb.GlossaryEntry, error)
354 DeleteGlossaryEntry(context.Context, *translatepb.DeleteGlossaryEntryRequest, ...gax.CallOption) error
355 CreateDataset(context.Context, *translatepb.CreateDatasetRequest, ...gax.CallOption) (*CreateDatasetOperation, error)
356 CreateDatasetOperation(name string) *CreateDatasetOperation
357 GetDataset(context.Context, *translatepb.GetDatasetRequest, ...gax.CallOption) (*translatepb.Dataset, error)
358 ListDatasets(context.Context, *translatepb.ListDatasetsRequest, ...gax.CallOption) *DatasetIterator
359 DeleteDataset(context.Context, *translatepb.DeleteDatasetRequest, ...gax.CallOption) (*DeleteDatasetOperation, error)
360 DeleteDatasetOperation(name string) *DeleteDatasetOperation
361 CreateAdaptiveMtDataset(context.Context, *translatepb.CreateAdaptiveMtDatasetRequest, ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error)
362 DeleteAdaptiveMtDataset(context.Context, *translatepb.DeleteAdaptiveMtDatasetRequest, ...gax.CallOption) error
363 GetAdaptiveMtDataset(context.Context, *translatepb.GetAdaptiveMtDatasetRequest, ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error)
364 ListAdaptiveMtDatasets(context.Context, *translatepb.ListAdaptiveMtDatasetsRequest, ...gax.CallOption) *AdaptiveMtDatasetIterator
365 AdaptiveMtTranslate(context.Context, *translatepb.AdaptiveMtTranslateRequest, ...gax.CallOption) (*translatepb.AdaptiveMtTranslateResponse, error)
366 GetAdaptiveMtFile(context.Context, *translatepb.GetAdaptiveMtFileRequest, ...gax.CallOption) (*translatepb.AdaptiveMtFile, error)
367 DeleteAdaptiveMtFile(context.Context, *translatepb.DeleteAdaptiveMtFileRequest, ...gax.CallOption) error
368 ImportAdaptiveMtFile(context.Context, *translatepb.ImportAdaptiveMtFileRequest, ...gax.CallOption) (*translatepb.ImportAdaptiveMtFileResponse, error)
369 ListAdaptiveMtFiles(context.Context, *translatepb.ListAdaptiveMtFilesRequest, ...gax.CallOption) *AdaptiveMtFileIterator
370 ListAdaptiveMtSentences(context.Context, *translatepb.ListAdaptiveMtSentencesRequest, ...gax.CallOption) *AdaptiveMtSentenceIterator
371 ImportData(context.Context, *translatepb.ImportDataRequest, ...gax.CallOption) (*ImportDataOperation, error)
372 ImportDataOperation(name string) *ImportDataOperation
373 ExportData(context.Context, *translatepb.ExportDataRequest, ...gax.CallOption) (*ExportDataOperation, error)
374 ExportDataOperation(name string) *ExportDataOperation
375 ListExamples(context.Context, *translatepb.ListExamplesRequest, ...gax.CallOption) *ExampleIterator
376 CreateModel(context.Context, *translatepb.CreateModelRequest, ...gax.CallOption) (*CreateModelOperation, error)
377 CreateModelOperation(name string) *CreateModelOperation
378 ListModels(context.Context, *translatepb.ListModelsRequest, ...gax.CallOption) *ModelIterator
379 GetModel(context.Context, *translatepb.GetModelRequest, ...gax.CallOption) (*translatepb.Model, error)
380 DeleteModel(context.Context, *translatepb.DeleteModelRequest, ...gax.CallOption) (*DeleteModelOperation, error)
381 DeleteModelOperation(name string) *DeleteModelOperation
382 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
383 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
384 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
385 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
386 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
387 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
388 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
389 }
390
391 // TranslationClient is a client for interacting with Cloud Translation API.
392 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
393 //
394 // Provides natural language translation operations.
395 type TranslationClient struct {
396 // The internal transport-dependent client.
397 internalClient internalTranslationClient
398
399 // The call options for this service.
400 CallOptions *TranslationCallOptions
401
402 // LROClient is used internally to handle long-running operations.
403 // It is exposed so that its CallOptions can be modified if required.
404 // Users should not Close this client.
405 LROClient *lroauto.OperationsClient
406 }
407
408 // Wrapper methods routed to the internal client.
409
410 // Close closes the connection to the API service. The user should invoke this when
411 // the client is no longer required.
412 func (c *TranslationClient) Close() error {
413 return c.internalClient.Close()
414 }
415
416 // setGoogleClientInfo sets the name and version of the application in
417 // the `x-goog-api-client` header passed on each request. Intended for
418 // use by Google-written clients.
419 func (c *TranslationClient) setGoogleClientInfo(keyval ...string) {
420 c.internalClient.setGoogleClientInfo(keyval...)
421 }
422
423 // Connection returns a connection to the API service.
424 //
425 // Deprecated: Connections are now pooled so this method does not always
426 // return the same resource.
427 func (c *TranslationClient) Connection() *grpc.ClientConn {
428 return c.internalClient.Connection()
429 }
430
431 // TranslateText translates input text and returns translated text.
432 func (c *TranslationClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, opts ...gax.CallOption) (*translatepb.TranslateTextResponse, error) {
433 return c.internalClient.TranslateText(ctx, req, opts...)
434 }
435
436 // RomanizeText romanize input text written in non-Latin scripts to Latin text.
437 func (c *TranslationClient) RomanizeText(ctx context.Context, req *translatepb.RomanizeTextRequest, opts ...gax.CallOption) (*translatepb.RomanizeTextResponse, error) {
438 return c.internalClient.RomanizeText(ctx, req, opts...)
439 }
440
441 // DetectLanguage detects the language of text within a request.
442 func (c *TranslationClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, opts ...gax.CallOption) (*translatepb.DetectLanguageResponse, error) {
443 return c.internalClient.DetectLanguage(ctx, req, opts...)
444 }
445
446 // GetSupportedLanguages returns a list of supported languages for translation.
447 func (c *TranslationClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, opts ...gax.CallOption) (*translatepb.SupportedLanguages, error) {
448 return c.internalClient.GetSupportedLanguages(ctx, req, opts...)
449 }
450
451 // TranslateDocument translates documents in synchronous mode.
452 func (c *TranslationClient) TranslateDocument(ctx context.Context, req *translatepb.TranslateDocumentRequest, opts ...gax.CallOption) (*translatepb.TranslateDocumentResponse, error) {
453 return c.internalClient.TranslateDocument(ctx, req, opts...)
454 }
455
456 // BatchTranslateText translates a large volume of text in asynchronous batch mode.
457 // This function provides real-time output as the inputs are being processed.
458 // If caller cancels a request, the partial results (for an input file, it’s
459 // all or nothing) may still be available on the specified output location.
460 //
461 // This call returns immediately and you can
462 // use google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call.
463 func (c *TranslationClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, opts ...gax.CallOption) (*BatchTranslateTextOperation, error) {
464 return c.internalClient.BatchTranslateText(ctx, req, opts...)
465 }
466
467 // BatchTranslateTextOperation returns a new BatchTranslateTextOperation from a given name.
468 // The name must be that of a previously created BatchTranslateTextOperation, possibly from a different process.
469 func (c *TranslationClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation {
470 return c.internalClient.BatchTranslateTextOperation(name)
471 }
472
473 // BatchTranslateDocument translates a large volume of document in asynchronous batch mode.
474 // This function provides real-time output as the inputs are being processed.
475 // If caller cancels a request, the partial results (for an input file, it’s
476 // all or nothing) may still be available on the specified output location.
477 //
478 // This call returns immediately and you can use
479 // google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call.
480 func (c *TranslationClient) BatchTranslateDocument(ctx context.Context, req *translatepb.BatchTranslateDocumentRequest, opts ...gax.CallOption) (*BatchTranslateDocumentOperation, error) {
481 return c.internalClient.BatchTranslateDocument(ctx, req, opts...)
482 }
483
484 // BatchTranslateDocumentOperation returns a new BatchTranslateDocumentOperation from a given name.
485 // The name must be that of a previously created BatchTranslateDocumentOperation, possibly from a different process.
486 func (c *TranslationClient) BatchTranslateDocumentOperation(name string) *BatchTranslateDocumentOperation {
487 return c.internalClient.BatchTranslateDocumentOperation(name)
488 }
489
490 // CreateGlossary creates a glossary and returns the long-running operation. Returns
491 // NOT_FOUND, if the project doesn’t exist.
492 func (c *TranslationClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, opts ...gax.CallOption) (*CreateGlossaryOperation, error) {
493 return c.internalClient.CreateGlossary(ctx, req, opts...)
494 }
495
496 // CreateGlossaryOperation returns a new CreateGlossaryOperation from a given name.
497 // The name must be that of a previously created CreateGlossaryOperation, possibly from a different process.
498 func (c *TranslationClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation {
499 return c.internalClient.CreateGlossaryOperation(name)
500 }
501
502 // UpdateGlossary updates a glossary. A LRO is used since the update can be async if the
503 // glossary’s entry file is updated.
504 func (c *TranslationClient) UpdateGlossary(ctx context.Context, req *translatepb.UpdateGlossaryRequest, opts ...gax.CallOption) (*UpdateGlossaryOperation, error) {
505 return c.internalClient.UpdateGlossary(ctx, req, opts...)
506 }
507
508 // UpdateGlossaryOperation returns a new UpdateGlossaryOperation from a given name.
509 // The name must be that of a previously created UpdateGlossaryOperation, possibly from a different process.
510 func (c *TranslationClient) UpdateGlossaryOperation(name string) *UpdateGlossaryOperation {
511 return c.internalClient.UpdateGlossaryOperation(name)
512 }
513
514 // ListGlossaries lists glossaries in a project. Returns NOT_FOUND, if the project doesn’t
515 // exist.
516 func (c *TranslationClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, opts ...gax.CallOption) *GlossaryIterator {
517 return c.internalClient.ListGlossaries(ctx, req, opts...)
518 }
519
520 // GetGlossary gets a glossary. Returns NOT_FOUND, if the glossary doesn’t
521 // exist.
522 func (c *TranslationClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, opts ...gax.CallOption) (*translatepb.Glossary, error) {
523 return c.internalClient.GetGlossary(ctx, req, opts...)
524 }
525
526 // DeleteGlossary deletes a glossary, or cancels glossary construction
527 // if the glossary isn’t created yet.
528 // Returns NOT_FOUND, if the glossary doesn’t exist.
529 func (c *TranslationClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, opts ...gax.CallOption) (*DeleteGlossaryOperation, error) {
530 return c.internalClient.DeleteGlossary(ctx, req, opts...)
531 }
532
533 // DeleteGlossaryOperation returns a new DeleteGlossaryOperation from a given name.
534 // The name must be that of a previously created DeleteGlossaryOperation, possibly from a different process.
535 func (c *TranslationClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation {
536 return c.internalClient.DeleteGlossaryOperation(name)
537 }
538
539 // GetGlossaryEntry gets a single glossary entry by the given id.
540 func (c *TranslationClient) GetGlossaryEntry(ctx context.Context, req *translatepb.GetGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
541 return c.internalClient.GetGlossaryEntry(ctx, req, opts...)
542 }
543
544 // ListGlossaryEntries list the entries for the glossary.
545 func (c *TranslationClient) ListGlossaryEntries(ctx context.Context, req *translatepb.ListGlossaryEntriesRequest, opts ...gax.CallOption) *GlossaryEntryIterator {
546 return c.internalClient.ListGlossaryEntries(ctx, req, opts...)
547 }
548
549 // CreateGlossaryEntry creates a glossary entry.
550 func (c *TranslationClient) CreateGlossaryEntry(ctx context.Context, req *translatepb.CreateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
551 return c.internalClient.CreateGlossaryEntry(ctx, req, opts...)
552 }
553
554 // UpdateGlossaryEntry updates a glossary entry.
555 func (c *TranslationClient) UpdateGlossaryEntry(ctx context.Context, req *translatepb.UpdateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
556 return c.internalClient.UpdateGlossaryEntry(ctx, req, opts...)
557 }
558
559 // DeleteGlossaryEntry deletes a single entry from the glossary
560 func (c *TranslationClient) DeleteGlossaryEntry(ctx context.Context, req *translatepb.DeleteGlossaryEntryRequest, opts ...gax.CallOption) error {
561 return c.internalClient.DeleteGlossaryEntry(ctx, req, opts...)
562 }
563
564 // CreateDataset creates a Dataset.
565 func (c *TranslationClient) CreateDataset(ctx context.Context, req *translatepb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) {
566 return c.internalClient.CreateDataset(ctx, req, opts...)
567 }
568
569 // CreateDatasetOperation returns a new CreateDatasetOperation from a given name.
570 // The name must be that of a previously created CreateDatasetOperation, possibly from a different process.
571 func (c *TranslationClient) CreateDatasetOperation(name string) *CreateDatasetOperation {
572 return c.internalClient.CreateDatasetOperation(name)
573 }
574
575 // GetDataset gets a Dataset.
576 func (c *TranslationClient) GetDataset(ctx context.Context, req *translatepb.GetDatasetRequest, opts ...gax.CallOption) (*translatepb.Dataset, error) {
577 return c.internalClient.GetDataset(ctx, req, opts...)
578 }
579
580 // ListDatasets lists datasets.
581 func (c *TranslationClient) ListDatasets(ctx context.Context, req *translatepb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator {
582 return c.internalClient.ListDatasets(ctx, req, opts...)
583 }
584
585 // DeleteDataset deletes a dataset and all of its contents.
586 func (c *TranslationClient) DeleteDataset(ctx context.Context, req *translatepb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) {
587 return c.internalClient.DeleteDataset(ctx, req, opts...)
588 }
589
590 // DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name.
591 // The name must be that of a previously created DeleteDatasetOperation, possibly from a different process.
592 func (c *TranslationClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation {
593 return c.internalClient.DeleteDatasetOperation(name)
594 }
595
596 // CreateAdaptiveMtDataset creates an Adaptive MT dataset.
597 func (c *TranslationClient) CreateAdaptiveMtDataset(ctx context.Context, req *translatepb.CreateAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
598 return c.internalClient.CreateAdaptiveMtDataset(ctx, req, opts...)
599 }
600
601 // DeleteAdaptiveMtDataset deletes an Adaptive MT dataset, including all its entries and associated
602 // metadata.
603 func (c *TranslationClient) DeleteAdaptiveMtDataset(ctx context.Context, req *translatepb.DeleteAdaptiveMtDatasetRequest, opts ...gax.CallOption) error {
604 return c.internalClient.DeleteAdaptiveMtDataset(ctx, req, opts...)
605 }
606
607 // GetAdaptiveMtDataset gets the Adaptive MT dataset.
608 func (c *TranslationClient) GetAdaptiveMtDataset(ctx context.Context, req *translatepb.GetAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
609 return c.internalClient.GetAdaptiveMtDataset(ctx, req, opts...)
610 }
611
612 // ListAdaptiveMtDatasets lists all Adaptive MT datasets for which the caller has read permission.
613 func (c *TranslationClient) ListAdaptiveMtDatasets(ctx context.Context, req *translatepb.ListAdaptiveMtDatasetsRequest, opts ...gax.CallOption) *AdaptiveMtDatasetIterator {
614 return c.internalClient.ListAdaptiveMtDatasets(ctx, req, opts...)
615 }
616
617 // AdaptiveMtTranslate translate text using Adaptive MT.
618 func (c *TranslationClient) AdaptiveMtTranslate(ctx context.Context, req *translatepb.AdaptiveMtTranslateRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtTranslateResponse, error) {
619 return c.internalClient.AdaptiveMtTranslate(ctx, req, opts...)
620 }
621
622 // GetAdaptiveMtFile gets and AdaptiveMtFile
623 func (c *TranslationClient) GetAdaptiveMtFile(ctx context.Context, req *translatepb.GetAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtFile, error) {
624 return c.internalClient.GetAdaptiveMtFile(ctx, req, opts...)
625 }
626
627 // DeleteAdaptiveMtFile deletes an AdaptiveMtFile along with its sentences.
628 func (c *TranslationClient) DeleteAdaptiveMtFile(ctx context.Context, req *translatepb.DeleteAdaptiveMtFileRequest, opts ...gax.CallOption) error {
629 return c.internalClient.DeleteAdaptiveMtFile(ctx, req, opts...)
630 }
631
632 // ImportAdaptiveMtFile imports an AdaptiveMtFile and adds all of its sentences into the
633 // AdaptiveMtDataset.
634 func (c *TranslationClient) ImportAdaptiveMtFile(ctx context.Context, req *translatepb.ImportAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.ImportAdaptiveMtFileResponse, error) {
635 return c.internalClient.ImportAdaptiveMtFile(ctx, req, opts...)
636 }
637
638 // ListAdaptiveMtFiles lists all AdaptiveMtFiles associated to an AdaptiveMtDataset.
639 func (c *TranslationClient) ListAdaptiveMtFiles(ctx context.Context, req *translatepb.ListAdaptiveMtFilesRequest, opts ...gax.CallOption) *AdaptiveMtFileIterator {
640 return c.internalClient.ListAdaptiveMtFiles(ctx, req, opts...)
641 }
642
643 // ListAdaptiveMtSentences lists all AdaptiveMtSentences under a given file/dataset.
644 func (c *TranslationClient) ListAdaptiveMtSentences(ctx context.Context, req *translatepb.ListAdaptiveMtSentencesRequest, opts ...gax.CallOption) *AdaptiveMtSentenceIterator {
645 return c.internalClient.ListAdaptiveMtSentences(ctx, req, opts...)
646 }
647
648 // ImportData import sentence pairs into translation Dataset.
649 func (c *TranslationClient) ImportData(ctx context.Context, req *translatepb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) {
650 return c.internalClient.ImportData(ctx, req, opts...)
651 }
652
653 // ImportDataOperation returns a new ImportDataOperation from a given name.
654 // The name must be that of a previously created ImportDataOperation, possibly from a different process.
655 func (c *TranslationClient) ImportDataOperation(name string) *ImportDataOperation {
656 return c.internalClient.ImportDataOperation(name)
657 }
658
659 // ExportData exports dataset’s data to the provided output location.
660 func (c *TranslationClient) ExportData(ctx context.Context, req *translatepb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) {
661 return c.internalClient.ExportData(ctx, req, opts...)
662 }
663
664 // ExportDataOperation returns a new ExportDataOperation from a given name.
665 // The name must be that of a previously created ExportDataOperation, possibly from a different process.
666 func (c *TranslationClient) ExportDataOperation(name string) *ExportDataOperation {
667 return c.internalClient.ExportDataOperation(name)
668 }
669
670 // ListExamples lists sentence pairs in the dataset.
671 func (c *TranslationClient) ListExamples(ctx context.Context, req *translatepb.ListExamplesRequest, opts ...gax.CallOption) *ExampleIterator {
672 return c.internalClient.ListExamples(ctx, req, opts...)
673 }
674
675 // CreateModel creates a Model.
676 func (c *TranslationClient) CreateModel(ctx context.Context, req *translatepb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) {
677 return c.internalClient.CreateModel(ctx, req, opts...)
678 }
679
680 // CreateModelOperation returns a new CreateModelOperation from a given name.
681 // The name must be that of a previously created CreateModelOperation, possibly from a different process.
682 func (c *TranslationClient) CreateModelOperation(name string) *CreateModelOperation {
683 return c.internalClient.CreateModelOperation(name)
684 }
685
686 // ListModels lists models.
687 func (c *TranslationClient) ListModels(ctx context.Context, req *translatepb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator {
688 return c.internalClient.ListModels(ctx, req, opts...)
689 }
690
691 // GetModel gets a model.
692 func (c *TranslationClient) GetModel(ctx context.Context, req *translatepb.GetModelRequest, opts ...gax.CallOption) (*translatepb.Model, error) {
693 return c.internalClient.GetModel(ctx, req, opts...)
694 }
695
696 // DeleteModel deletes a model.
697 func (c *TranslationClient) DeleteModel(ctx context.Context, req *translatepb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) {
698 return c.internalClient.DeleteModel(ctx, req, opts...)
699 }
700
701 // DeleteModelOperation returns a new DeleteModelOperation from a given name.
702 // The name must be that of a previously created DeleteModelOperation, possibly from a different process.
703 func (c *TranslationClient) DeleteModelOperation(name string) *DeleteModelOperation {
704 return c.internalClient.DeleteModelOperation(name)
705 }
706
707 // GetLocation gets information about a location.
708 func (c *TranslationClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
709 return c.internalClient.GetLocation(ctx, req, opts...)
710 }
711
712 // ListLocations lists information about the supported locations for this service.
713 func (c *TranslationClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
714 return c.internalClient.ListLocations(ctx, req, opts...)
715 }
716
717 // CancelOperation is a utility method from google.longrunning.Operations.
718 func (c *TranslationClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
719 return c.internalClient.CancelOperation(ctx, req, opts...)
720 }
721
722 // DeleteOperation is a utility method from google.longrunning.Operations.
723 func (c *TranslationClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
724 return c.internalClient.DeleteOperation(ctx, req, opts...)
725 }
726
727 // GetOperation is a utility method from google.longrunning.Operations.
728 func (c *TranslationClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
729 return c.internalClient.GetOperation(ctx, req, opts...)
730 }
731
732 // ListOperations is a utility method from google.longrunning.Operations.
733 func (c *TranslationClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
734 return c.internalClient.ListOperations(ctx, req, opts...)
735 }
736
737 // WaitOperation is a utility method from google.longrunning.Operations.
738 func (c *TranslationClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
739 return c.internalClient.WaitOperation(ctx, req, opts...)
740 }
741
742 // translationGRPCClient is a client for interacting with Cloud Translation API over gRPC transport.
743 //
744 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
745 type translationGRPCClient struct {
746 // Connection pool of gRPC connections to the service.
747 connPool gtransport.ConnPool
748
749 // Points back to the CallOptions field of the containing TranslationClient
750 CallOptions **TranslationCallOptions
751
752 // The gRPC API client.
753 translationClient translatepb.TranslationServiceClient
754
755 // LROClient is used internally to handle long-running operations.
756 // It is exposed so that its CallOptions can be modified if required.
757 // Users should not Close this client.
758 LROClient **lroauto.OperationsClient
759
760 operationsClient longrunningpb.OperationsClient
761
762 locationsClient locationpb.LocationsClient
763
764 // The x-goog-* metadata to be sent with each request.
765 xGoogHeaders []string
766
767 logger *slog.Logger
768 }
769
770 // NewTranslationClient creates a new translation service client based on gRPC.
771 // The returned client must be Closed when it is done being used to clean up its underlying connections.
772 //
773 // Provides natural language translation operations.
774 func NewTranslationClient(ctx context.Context, opts ...option.ClientOption) (*TranslationClient, error) {
775 clientOpts := defaultTranslationGRPCClientOptions()
776 if newTranslationClientHook != nil {
777 hookOpts, err := newTranslationClientHook(ctx, clientHookParams{})
778 if err != nil {
779 return nil, err
780 }
781 clientOpts = append(clientOpts, hookOpts...)
782 }
783
784 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
785 if err != nil {
786 return nil, err
787 }
788 client := TranslationClient{CallOptions: defaultTranslationCallOptions()}
789
790 c := &translationGRPCClient{
791 connPool: connPool,
792 translationClient: translatepb.NewTranslationServiceClient(connPool),
793 CallOptions: &client.CallOptions,
794 logger: internaloption.GetLogger(opts),
795 operationsClient: longrunningpb.NewOperationsClient(connPool),
796 locationsClient: locationpb.NewLocationsClient(connPool),
797 }
798 c.setGoogleClientInfo()
799
800 client.internalClient = c
801
802 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
803 if err != nil {
804 // This error "should not happen", since we are just reusing old connection pool
805 // and never actually need to dial.
806 // If this does happen, we could leak connp. However, we cannot close conn:
807 // If the user invoked the constructor with option.WithGRPCConn,
808 // we would close a connection that's still in use.
809 // TODO: investigate error conditions.
810 return nil, err
811 }
812 c.LROClient = &client.LROClient
813 return &client, nil
814 }
815
816 // Connection returns a connection to the API service.
817 //
818 // Deprecated: Connections are now pooled so this method does not always
819 // return the same resource.
820 func (c *translationGRPCClient) Connection() *grpc.ClientConn {
821 return c.connPool.Conn()
822 }
823
824 // setGoogleClientInfo sets the name and version of the application in
825 // the `x-goog-api-client` header passed on each request. Intended for
826 // use by Google-written clients.
827 func (c *translationGRPCClient) setGoogleClientInfo(keyval ...string) {
828 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
829 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
830 c.xGoogHeaders = []string{
831 "x-goog-api-client", gax.XGoogHeader(kv...),
832 }
833 }
834
835 // Close closes the connection to the API service. The user should invoke this when
836 // the client is no longer required.
837 func (c *translationGRPCClient) Close() error {
838 return c.connPool.Close()
839 }
840
841 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
842 type translationRESTClient struct {
843 // The http endpoint to connect to.
844 endpoint string
845
846 // The http client.
847 httpClient *http.Client
848
849 // LROClient is used internally to handle long-running operations.
850 // It is exposed so that its CallOptions can be modified if required.
851 // Users should not Close this client.
852 LROClient **lroauto.OperationsClient
853
854 // The x-goog-* headers to be sent with each request.
855 xGoogHeaders []string
856
857 // Points back to the CallOptions field of the containing TranslationClient
858 CallOptions **TranslationCallOptions
859
860 logger *slog.Logger
861 }
862
863 // NewTranslationRESTClient creates a new translation service rest client.
864 //
865 // Provides natural language translation operations.
866 func NewTranslationRESTClient(ctx context.Context, opts ...option.ClientOption) (*TranslationClient, error) {
867 clientOpts := append(defaultTranslationRESTClientOptions(), opts...)
868 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
869 if err != nil {
870 return nil, err
871 }
872
873 callOpts := defaultTranslationRESTCallOptions()
874 c := &translationRESTClient{
875 endpoint: endpoint,
876 httpClient: httpClient,
877 CallOptions: &callOpts,
878 logger: internaloption.GetLogger(opts),
879 }
880 c.setGoogleClientInfo()
881
882 lroOpts := []option.ClientOption{
883 option.WithHTTPClient(httpClient),
884 option.WithEndpoint(endpoint),
885 }
886 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
887 if err != nil {
888 return nil, err
889 }
890 c.LROClient = &opClient
891
892 return &TranslationClient{internalClient: c, CallOptions: callOpts}, nil
893 }
894
895 func defaultTranslationRESTClientOptions() []option.ClientOption {
896 return []option.ClientOption{
897 internaloption.WithDefaultEndpoint("https://translate.googleapis.com"),
898 internaloption.WithDefaultEndpointTemplate("https://translate.UNIVERSE_DOMAIN"),
899 internaloption.WithDefaultMTLSEndpoint("https://translate.mtls.googleapis.com"),
900 internaloption.WithDefaultUniverseDomain("googleapis.com"),
901 internaloption.WithDefaultAudience("https://translate.googleapis.com/"),
902 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
903 internaloption.EnableNewAuthLibrary(),
904 }
905 }
906
907 // setGoogleClientInfo sets the name and version of the application in
908 // the `x-goog-api-client` header passed on each request. Intended for
909 // use by Google-written clients.
910 func (c *translationRESTClient) setGoogleClientInfo(keyval ...string) {
911 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
912 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
913 c.xGoogHeaders = []string{
914 "x-goog-api-client", gax.XGoogHeader(kv...),
915 }
916 }
917
918 // Close closes the connection to the API service. The user should invoke this when
919 // the client is no longer required.
920 func (c *translationRESTClient) Close() error {
921 // Replace httpClient with nil to force cleanup.
922 c.httpClient = nil
923 return nil
924 }
925
926 // Connection returns a connection to the API service.
927 //
928 // Deprecated: This method always returns nil.
929 func (c *translationRESTClient) Connection() *grpc.ClientConn {
930 return nil
931 }
932 func (c *translationGRPCClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, opts ...gax.CallOption) (*translatepb.TranslateTextResponse, error) {
933 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
934
935 hds = append(c.xGoogHeaders, hds...)
936 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
937 opts = append((*c.CallOptions).TranslateText[0:len((*c.CallOptions).TranslateText):len((*c.CallOptions).TranslateText)], opts...)
938 var resp *translatepb.TranslateTextResponse
939 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
940 var err error
941 resp, err = executeRPC(ctx, c.translationClient.TranslateText, req, settings.GRPC, c.logger, "TranslateText")
942 return err
943 }, opts...)
944 if err != nil {
945 return nil, err
946 }
947 return resp, nil
948 }
949
950 func (c *translationGRPCClient) RomanizeText(ctx context.Context, req *translatepb.RomanizeTextRequest, opts ...gax.CallOption) (*translatepb.RomanizeTextResponse, error) {
951 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
952
953 hds = append(c.xGoogHeaders, hds...)
954 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
955 opts = append((*c.CallOptions).RomanizeText[0:len((*c.CallOptions).RomanizeText):len((*c.CallOptions).RomanizeText)], opts...)
956 var resp *translatepb.RomanizeTextResponse
957 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
958 var err error
959 resp, err = executeRPC(ctx, c.translationClient.RomanizeText, req, settings.GRPC, c.logger, "RomanizeText")
960 return err
961 }, opts...)
962 if err != nil {
963 return nil, err
964 }
965 return resp, nil
966 }
967
968 func (c *translationGRPCClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, opts ...gax.CallOption) (*translatepb.DetectLanguageResponse, error) {
969 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
970
971 hds = append(c.xGoogHeaders, hds...)
972 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
973 opts = append((*c.CallOptions).DetectLanguage[0:len((*c.CallOptions).DetectLanguage):len((*c.CallOptions).DetectLanguage)], opts...)
974 var resp *translatepb.DetectLanguageResponse
975 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
976 var err error
977 resp, err = executeRPC(ctx, c.translationClient.DetectLanguage, req, settings.GRPC, c.logger, "DetectLanguage")
978 return err
979 }, opts...)
980 if err != nil {
981 return nil, err
982 }
983 return resp, nil
984 }
985
986 func (c *translationGRPCClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, opts ...gax.CallOption) (*translatepb.SupportedLanguages, error) {
987 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
988
989 hds = append(c.xGoogHeaders, hds...)
990 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
991 opts = append((*c.CallOptions).GetSupportedLanguages[0:len((*c.CallOptions).GetSupportedLanguages):len((*c.CallOptions).GetSupportedLanguages)], opts...)
992 var resp *translatepb.SupportedLanguages
993 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
994 var err error
995 resp, err = executeRPC(ctx, c.translationClient.GetSupportedLanguages, req, settings.GRPC, c.logger, "GetSupportedLanguages")
996 return err
997 }, opts...)
998 if err != nil {
999 return nil, err
1000 }
1001 return resp, nil
1002 }
1003
1004 func (c *translationGRPCClient) TranslateDocument(ctx context.Context, req *translatepb.TranslateDocumentRequest, opts ...gax.CallOption) (*translatepb.TranslateDocumentResponse, error) {
1005 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1006
1007 hds = append(c.xGoogHeaders, hds...)
1008 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1009 opts = append((*c.CallOptions).TranslateDocument[0:len((*c.CallOptions).TranslateDocument):len((*c.CallOptions).TranslateDocument)], opts...)
1010 var resp *translatepb.TranslateDocumentResponse
1011 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1012 var err error
1013 resp, err = executeRPC(ctx, c.translationClient.TranslateDocument, req, settings.GRPC, c.logger, "TranslateDocument")
1014 return err
1015 }, opts...)
1016 if err != nil {
1017 return nil, err
1018 }
1019 return resp, nil
1020 }
1021
1022 func (c *translationGRPCClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, opts ...gax.CallOption) (*BatchTranslateTextOperation, error) {
1023 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1024
1025 hds = append(c.xGoogHeaders, hds...)
1026 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1027 opts = append((*c.CallOptions).BatchTranslateText[0:len((*c.CallOptions).BatchTranslateText):len((*c.CallOptions).BatchTranslateText)], opts...)
1028 var resp *longrunningpb.Operation
1029 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1030 var err error
1031 resp, err = executeRPC(ctx, c.translationClient.BatchTranslateText, req, settings.GRPC, c.logger, "BatchTranslateText")
1032 return err
1033 }, opts...)
1034 if err != nil {
1035 return nil, err
1036 }
1037 return &BatchTranslateTextOperation{
1038 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1039 }, nil
1040 }
1041
1042 func (c *translationGRPCClient) BatchTranslateDocument(ctx context.Context, req *translatepb.BatchTranslateDocumentRequest, opts ...gax.CallOption) (*BatchTranslateDocumentOperation, error) {
1043 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1044
1045 hds = append(c.xGoogHeaders, hds...)
1046 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1047 opts = append((*c.CallOptions).BatchTranslateDocument[0:len((*c.CallOptions).BatchTranslateDocument):len((*c.CallOptions).BatchTranslateDocument)], opts...)
1048 var resp *longrunningpb.Operation
1049 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1050 var err error
1051 resp, err = executeRPC(ctx, c.translationClient.BatchTranslateDocument, req, settings.GRPC, c.logger, "BatchTranslateDocument")
1052 return err
1053 }, opts...)
1054 if err != nil {
1055 return nil, err
1056 }
1057 return &BatchTranslateDocumentOperation{
1058 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1059 }, nil
1060 }
1061
1062 func (c *translationGRPCClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, opts ...gax.CallOption) (*CreateGlossaryOperation, error) {
1063 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1064
1065 hds = append(c.xGoogHeaders, hds...)
1066 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1067 opts = append((*c.CallOptions).CreateGlossary[0:len((*c.CallOptions).CreateGlossary):len((*c.CallOptions).CreateGlossary)], opts...)
1068 var resp *longrunningpb.Operation
1069 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1070 var err error
1071 resp, err = executeRPC(ctx, c.translationClient.CreateGlossary, req, settings.GRPC, c.logger, "CreateGlossary")
1072 return err
1073 }, opts...)
1074 if err != nil {
1075 return nil, err
1076 }
1077 return &CreateGlossaryOperation{
1078 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1079 }, nil
1080 }
1081
1082 func (c *translationGRPCClient) UpdateGlossary(ctx context.Context, req *translatepb.UpdateGlossaryRequest, opts ...gax.CallOption) (*UpdateGlossaryOperation, error) {
1083 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "glossary.name", url.QueryEscape(req.GetGlossary().GetName()))}
1084
1085 hds = append(c.xGoogHeaders, hds...)
1086 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1087 opts = append((*c.CallOptions).UpdateGlossary[0:len((*c.CallOptions).UpdateGlossary):len((*c.CallOptions).UpdateGlossary)], opts...)
1088 var resp *longrunningpb.Operation
1089 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1090 var err error
1091 resp, err = executeRPC(ctx, c.translationClient.UpdateGlossary, req, settings.GRPC, c.logger, "UpdateGlossary")
1092 return err
1093 }, opts...)
1094 if err != nil {
1095 return nil, err
1096 }
1097 return &UpdateGlossaryOperation{
1098 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1099 }, nil
1100 }
1101
1102 func (c *translationGRPCClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, opts ...gax.CallOption) *GlossaryIterator {
1103 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1104
1105 hds = append(c.xGoogHeaders, hds...)
1106 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1107 opts = append((*c.CallOptions).ListGlossaries[0:len((*c.CallOptions).ListGlossaries):len((*c.CallOptions).ListGlossaries)], opts...)
1108 it := &GlossaryIterator{}
1109 req = proto.Clone(req).(*translatepb.ListGlossariesRequest)
1110 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Glossary, string, error) {
1111 resp := &translatepb.ListGlossariesResponse{}
1112 if pageToken != "" {
1113 req.PageToken = pageToken
1114 }
1115 if pageSize > math.MaxInt32 {
1116 req.PageSize = math.MaxInt32
1117 } else if pageSize != 0 {
1118 req.PageSize = int32(pageSize)
1119 }
1120 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1121 var err error
1122 resp, err = executeRPC(ctx, c.translationClient.ListGlossaries, req, settings.GRPC, c.logger, "ListGlossaries")
1123 return err
1124 }, opts...)
1125 if err != nil {
1126 return nil, "", err
1127 }
1128
1129 it.Response = resp
1130 return resp.GetGlossaries(), resp.GetNextPageToken(), nil
1131 }
1132 fetch := func(pageSize int, pageToken string) (string, error) {
1133 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1134 if err != nil {
1135 return "", err
1136 }
1137 it.items = append(it.items, items...)
1138 return nextPageToken, nil
1139 }
1140
1141 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1142 it.pageInfo.MaxSize = int(req.GetPageSize())
1143 it.pageInfo.Token = req.GetPageToken()
1144
1145 return it
1146 }
1147
1148 func (c *translationGRPCClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, opts ...gax.CallOption) (*translatepb.Glossary, error) {
1149 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1150
1151 hds = append(c.xGoogHeaders, hds...)
1152 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1153 opts = append((*c.CallOptions).GetGlossary[0:len((*c.CallOptions).GetGlossary):len((*c.CallOptions).GetGlossary)], opts...)
1154 var resp *translatepb.Glossary
1155 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1156 var err error
1157 resp, err = executeRPC(ctx, c.translationClient.GetGlossary, req, settings.GRPC, c.logger, "GetGlossary")
1158 return err
1159 }, opts...)
1160 if err != nil {
1161 return nil, err
1162 }
1163 return resp, nil
1164 }
1165
1166 func (c *translationGRPCClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, opts ...gax.CallOption) (*DeleteGlossaryOperation, error) {
1167 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1168
1169 hds = append(c.xGoogHeaders, hds...)
1170 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1171 opts = append((*c.CallOptions).DeleteGlossary[0:len((*c.CallOptions).DeleteGlossary):len((*c.CallOptions).DeleteGlossary)], opts...)
1172 var resp *longrunningpb.Operation
1173 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1174 var err error
1175 resp, err = executeRPC(ctx, c.translationClient.DeleteGlossary, req, settings.GRPC, c.logger, "DeleteGlossary")
1176 return err
1177 }, opts...)
1178 if err != nil {
1179 return nil, err
1180 }
1181 return &DeleteGlossaryOperation{
1182 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1183 }, nil
1184 }
1185
1186 func (c *translationGRPCClient) GetGlossaryEntry(ctx context.Context, req *translatepb.GetGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
1187 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1188
1189 hds = append(c.xGoogHeaders, hds...)
1190 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1191 opts = append((*c.CallOptions).GetGlossaryEntry[0:len((*c.CallOptions).GetGlossaryEntry):len((*c.CallOptions).GetGlossaryEntry)], opts...)
1192 var resp *translatepb.GlossaryEntry
1193 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1194 var err error
1195 resp, err = executeRPC(ctx, c.translationClient.GetGlossaryEntry, req, settings.GRPC, c.logger, "GetGlossaryEntry")
1196 return err
1197 }, opts...)
1198 if err != nil {
1199 return nil, err
1200 }
1201 return resp, nil
1202 }
1203
1204 func (c *translationGRPCClient) ListGlossaryEntries(ctx context.Context, req *translatepb.ListGlossaryEntriesRequest, opts ...gax.CallOption) *GlossaryEntryIterator {
1205 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1206
1207 hds = append(c.xGoogHeaders, hds...)
1208 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1209 opts = append((*c.CallOptions).ListGlossaryEntries[0:len((*c.CallOptions).ListGlossaryEntries):len((*c.CallOptions).ListGlossaryEntries)], opts...)
1210 it := &GlossaryEntryIterator{}
1211 req = proto.Clone(req).(*translatepb.ListGlossaryEntriesRequest)
1212 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.GlossaryEntry, string, error) {
1213 resp := &translatepb.ListGlossaryEntriesResponse{}
1214 if pageToken != "" {
1215 req.PageToken = pageToken
1216 }
1217 if pageSize > math.MaxInt32 {
1218 req.PageSize = math.MaxInt32
1219 } else if pageSize != 0 {
1220 req.PageSize = int32(pageSize)
1221 }
1222 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1223 var err error
1224 resp, err = executeRPC(ctx, c.translationClient.ListGlossaryEntries, req, settings.GRPC, c.logger, "ListGlossaryEntries")
1225 return err
1226 }, opts...)
1227 if err != nil {
1228 return nil, "", err
1229 }
1230
1231 it.Response = resp
1232 return resp.GetGlossaryEntries(), resp.GetNextPageToken(), nil
1233 }
1234 fetch := func(pageSize int, pageToken string) (string, error) {
1235 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1236 if err != nil {
1237 return "", err
1238 }
1239 it.items = append(it.items, items...)
1240 return nextPageToken, nil
1241 }
1242
1243 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1244 it.pageInfo.MaxSize = int(req.GetPageSize())
1245 it.pageInfo.Token = req.GetPageToken()
1246
1247 return it
1248 }
1249
1250 func (c *translationGRPCClient) CreateGlossaryEntry(ctx context.Context, req *translatepb.CreateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
1251 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1252
1253 hds = append(c.xGoogHeaders, hds...)
1254 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1255 opts = append((*c.CallOptions).CreateGlossaryEntry[0:len((*c.CallOptions).CreateGlossaryEntry):len((*c.CallOptions).CreateGlossaryEntry)], opts...)
1256 var resp *translatepb.GlossaryEntry
1257 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1258 var err error
1259 resp, err = executeRPC(ctx, c.translationClient.CreateGlossaryEntry, req, settings.GRPC, c.logger, "CreateGlossaryEntry")
1260 return err
1261 }, opts...)
1262 if err != nil {
1263 return nil, err
1264 }
1265 return resp, nil
1266 }
1267
1268 func (c *translationGRPCClient) UpdateGlossaryEntry(ctx context.Context, req *translatepb.UpdateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
1269 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "glossary_entry.name", url.QueryEscape(req.GetGlossaryEntry().GetName()))}
1270
1271 hds = append(c.xGoogHeaders, hds...)
1272 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1273 opts = append((*c.CallOptions).UpdateGlossaryEntry[0:len((*c.CallOptions).UpdateGlossaryEntry):len((*c.CallOptions).UpdateGlossaryEntry)], opts...)
1274 var resp *translatepb.GlossaryEntry
1275 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1276 var err error
1277 resp, err = executeRPC(ctx, c.translationClient.UpdateGlossaryEntry, req, settings.GRPC, c.logger, "UpdateGlossaryEntry")
1278 return err
1279 }, opts...)
1280 if err != nil {
1281 return nil, err
1282 }
1283 return resp, nil
1284 }
1285
1286 func (c *translationGRPCClient) DeleteGlossaryEntry(ctx context.Context, req *translatepb.DeleteGlossaryEntryRequest, opts ...gax.CallOption) error {
1287 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1288
1289 hds = append(c.xGoogHeaders, hds...)
1290 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1291 opts = append((*c.CallOptions).DeleteGlossaryEntry[0:len((*c.CallOptions).DeleteGlossaryEntry):len((*c.CallOptions).DeleteGlossaryEntry)], opts...)
1292 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1293 var err error
1294 _, err = executeRPC(ctx, c.translationClient.DeleteGlossaryEntry, req, settings.GRPC, c.logger, "DeleteGlossaryEntry")
1295 return err
1296 }, opts...)
1297 return err
1298 }
1299
1300 func (c *translationGRPCClient) CreateDataset(ctx context.Context, req *translatepb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) {
1301 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1302
1303 hds = append(c.xGoogHeaders, hds...)
1304 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1305 opts = append((*c.CallOptions).CreateDataset[0:len((*c.CallOptions).CreateDataset):len((*c.CallOptions).CreateDataset)], opts...)
1306 var resp *longrunningpb.Operation
1307 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1308 var err error
1309 resp, err = executeRPC(ctx, c.translationClient.CreateDataset, req, settings.GRPC, c.logger, "CreateDataset")
1310 return err
1311 }, opts...)
1312 if err != nil {
1313 return nil, err
1314 }
1315 return &CreateDatasetOperation{
1316 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1317 }, nil
1318 }
1319
1320 func (c *translationGRPCClient) GetDataset(ctx context.Context, req *translatepb.GetDatasetRequest, opts ...gax.CallOption) (*translatepb.Dataset, error) {
1321 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1322
1323 hds = append(c.xGoogHeaders, hds...)
1324 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1325 opts = append((*c.CallOptions).GetDataset[0:len((*c.CallOptions).GetDataset):len((*c.CallOptions).GetDataset)], opts...)
1326 var resp *translatepb.Dataset
1327 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1328 var err error
1329 resp, err = executeRPC(ctx, c.translationClient.GetDataset, req, settings.GRPC, c.logger, "GetDataset")
1330 return err
1331 }, opts...)
1332 if err != nil {
1333 return nil, err
1334 }
1335 return resp, nil
1336 }
1337
1338 func (c *translationGRPCClient) ListDatasets(ctx context.Context, req *translatepb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator {
1339 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1340
1341 hds = append(c.xGoogHeaders, hds...)
1342 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1343 opts = append((*c.CallOptions).ListDatasets[0:len((*c.CallOptions).ListDatasets):len((*c.CallOptions).ListDatasets)], opts...)
1344 it := &DatasetIterator{}
1345 req = proto.Clone(req).(*translatepb.ListDatasetsRequest)
1346 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Dataset, string, error) {
1347 resp := &translatepb.ListDatasetsResponse{}
1348 if pageToken != "" {
1349 req.PageToken = pageToken
1350 }
1351 if pageSize > math.MaxInt32 {
1352 req.PageSize = math.MaxInt32
1353 } else if pageSize != 0 {
1354 req.PageSize = int32(pageSize)
1355 }
1356 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1357 var err error
1358 resp, err = executeRPC(ctx, c.translationClient.ListDatasets, req, settings.GRPC, c.logger, "ListDatasets")
1359 return err
1360 }, opts...)
1361 if err != nil {
1362 return nil, "", err
1363 }
1364
1365 it.Response = resp
1366 return resp.GetDatasets(), resp.GetNextPageToken(), nil
1367 }
1368 fetch := func(pageSize int, pageToken string) (string, error) {
1369 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1370 if err != nil {
1371 return "", err
1372 }
1373 it.items = append(it.items, items...)
1374 return nextPageToken, nil
1375 }
1376
1377 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1378 it.pageInfo.MaxSize = int(req.GetPageSize())
1379 it.pageInfo.Token = req.GetPageToken()
1380
1381 return it
1382 }
1383
1384 func (c *translationGRPCClient) DeleteDataset(ctx context.Context, req *translatepb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) {
1385 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1386
1387 hds = append(c.xGoogHeaders, hds...)
1388 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1389 opts = append((*c.CallOptions).DeleteDataset[0:len((*c.CallOptions).DeleteDataset):len((*c.CallOptions).DeleteDataset)], opts...)
1390 var resp *longrunningpb.Operation
1391 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1392 var err error
1393 resp, err = executeRPC(ctx, c.translationClient.DeleteDataset, req, settings.GRPC, c.logger, "DeleteDataset")
1394 return err
1395 }, opts...)
1396 if err != nil {
1397 return nil, err
1398 }
1399 return &DeleteDatasetOperation{
1400 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1401 }, nil
1402 }
1403
1404 func (c *translationGRPCClient) CreateAdaptiveMtDataset(ctx context.Context, req *translatepb.CreateAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
1405 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1406
1407 hds = append(c.xGoogHeaders, hds...)
1408 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1409 opts = append((*c.CallOptions).CreateAdaptiveMtDataset[0:len((*c.CallOptions).CreateAdaptiveMtDataset):len((*c.CallOptions).CreateAdaptiveMtDataset)], opts...)
1410 var resp *translatepb.AdaptiveMtDataset
1411 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1412 var err error
1413 resp, err = executeRPC(ctx, c.translationClient.CreateAdaptiveMtDataset, req, settings.GRPC, c.logger, "CreateAdaptiveMtDataset")
1414 return err
1415 }, opts...)
1416 if err != nil {
1417 return nil, err
1418 }
1419 return resp, nil
1420 }
1421
1422 func (c *translationGRPCClient) DeleteAdaptiveMtDataset(ctx context.Context, req *translatepb.DeleteAdaptiveMtDatasetRequest, opts ...gax.CallOption) error {
1423 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1424
1425 hds = append(c.xGoogHeaders, hds...)
1426 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1427 opts = append((*c.CallOptions).DeleteAdaptiveMtDataset[0:len((*c.CallOptions).DeleteAdaptiveMtDataset):len((*c.CallOptions).DeleteAdaptiveMtDataset)], opts...)
1428 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1429 var err error
1430 _, err = executeRPC(ctx, c.translationClient.DeleteAdaptiveMtDataset, req, settings.GRPC, c.logger, "DeleteAdaptiveMtDataset")
1431 return err
1432 }, opts...)
1433 return err
1434 }
1435
1436 func (c *translationGRPCClient) GetAdaptiveMtDataset(ctx context.Context, req *translatepb.GetAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
1437 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1438
1439 hds = append(c.xGoogHeaders, hds...)
1440 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1441 opts = append((*c.CallOptions).GetAdaptiveMtDataset[0:len((*c.CallOptions).GetAdaptiveMtDataset):len((*c.CallOptions).GetAdaptiveMtDataset)], opts...)
1442 var resp *translatepb.AdaptiveMtDataset
1443 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1444 var err error
1445 resp, err = executeRPC(ctx, c.translationClient.GetAdaptiveMtDataset, req, settings.GRPC, c.logger, "GetAdaptiveMtDataset")
1446 return err
1447 }, opts...)
1448 if err != nil {
1449 return nil, err
1450 }
1451 return resp, nil
1452 }
1453
1454 func (c *translationGRPCClient) ListAdaptiveMtDatasets(ctx context.Context, req *translatepb.ListAdaptiveMtDatasetsRequest, opts ...gax.CallOption) *AdaptiveMtDatasetIterator {
1455 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1456
1457 hds = append(c.xGoogHeaders, hds...)
1458 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1459 opts = append((*c.CallOptions).ListAdaptiveMtDatasets[0:len((*c.CallOptions).ListAdaptiveMtDatasets):len((*c.CallOptions).ListAdaptiveMtDatasets)], opts...)
1460 it := &AdaptiveMtDatasetIterator{}
1461 req = proto.Clone(req).(*translatepb.ListAdaptiveMtDatasetsRequest)
1462 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtDataset, string, error) {
1463 resp := &translatepb.ListAdaptiveMtDatasetsResponse{}
1464 if pageToken != "" {
1465 req.PageToken = pageToken
1466 }
1467 if pageSize > math.MaxInt32 {
1468 req.PageSize = math.MaxInt32
1469 } else if pageSize != 0 {
1470 req.PageSize = int32(pageSize)
1471 }
1472 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1473 var err error
1474 resp, err = executeRPC(ctx, c.translationClient.ListAdaptiveMtDatasets, req, settings.GRPC, c.logger, "ListAdaptiveMtDatasets")
1475 return err
1476 }, opts...)
1477 if err != nil {
1478 return nil, "", err
1479 }
1480
1481 it.Response = resp
1482 return resp.GetAdaptiveMtDatasets(), resp.GetNextPageToken(), nil
1483 }
1484 fetch := func(pageSize int, pageToken string) (string, error) {
1485 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1486 if err != nil {
1487 return "", err
1488 }
1489 it.items = append(it.items, items...)
1490 return nextPageToken, nil
1491 }
1492
1493 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1494 it.pageInfo.MaxSize = int(req.GetPageSize())
1495 it.pageInfo.Token = req.GetPageToken()
1496
1497 return it
1498 }
1499
1500 func (c *translationGRPCClient) AdaptiveMtTranslate(ctx context.Context, req *translatepb.AdaptiveMtTranslateRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtTranslateResponse, error) {
1501 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1502
1503 hds = append(c.xGoogHeaders, hds...)
1504 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1505 opts = append((*c.CallOptions).AdaptiveMtTranslate[0:len((*c.CallOptions).AdaptiveMtTranslate):len((*c.CallOptions).AdaptiveMtTranslate)], opts...)
1506 var resp *translatepb.AdaptiveMtTranslateResponse
1507 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1508 var err error
1509 resp, err = executeRPC(ctx, c.translationClient.AdaptiveMtTranslate, req, settings.GRPC, c.logger, "AdaptiveMtTranslate")
1510 return err
1511 }, opts...)
1512 if err != nil {
1513 return nil, err
1514 }
1515 return resp, nil
1516 }
1517
1518 func (c *translationGRPCClient) GetAdaptiveMtFile(ctx context.Context, req *translatepb.GetAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtFile, error) {
1519 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1520
1521 hds = append(c.xGoogHeaders, hds...)
1522 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1523 opts = append((*c.CallOptions).GetAdaptiveMtFile[0:len((*c.CallOptions).GetAdaptiveMtFile):len((*c.CallOptions).GetAdaptiveMtFile)], opts...)
1524 var resp *translatepb.AdaptiveMtFile
1525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1526 var err error
1527 resp, err = executeRPC(ctx, c.translationClient.GetAdaptiveMtFile, req, settings.GRPC, c.logger, "GetAdaptiveMtFile")
1528 return err
1529 }, opts...)
1530 if err != nil {
1531 return nil, err
1532 }
1533 return resp, nil
1534 }
1535
1536 func (c *translationGRPCClient) DeleteAdaptiveMtFile(ctx context.Context, req *translatepb.DeleteAdaptiveMtFileRequest, opts ...gax.CallOption) error {
1537 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1538
1539 hds = append(c.xGoogHeaders, hds...)
1540 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1541 opts = append((*c.CallOptions).DeleteAdaptiveMtFile[0:len((*c.CallOptions).DeleteAdaptiveMtFile):len((*c.CallOptions).DeleteAdaptiveMtFile)], opts...)
1542 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1543 var err error
1544 _, err = executeRPC(ctx, c.translationClient.DeleteAdaptiveMtFile, req, settings.GRPC, c.logger, "DeleteAdaptiveMtFile")
1545 return err
1546 }, opts...)
1547 return err
1548 }
1549
1550 func (c *translationGRPCClient) ImportAdaptiveMtFile(ctx context.Context, req *translatepb.ImportAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.ImportAdaptiveMtFileResponse, error) {
1551 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1552
1553 hds = append(c.xGoogHeaders, hds...)
1554 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1555 opts = append((*c.CallOptions).ImportAdaptiveMtFile[0:len((*c.CallOptions).ImportAdaptiveMtFile):len((*c.CallOptions).ImportAdaptiveMtFile)], opts...)
1556 var resp *translatepb.ImportAdaptiveMtFileResponse
1557 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1558 var err error
1559 resp, err = executeRPC(ctx, c.translationClient.ImportAdaptiveMtFile, req, settings.GRPC, c.logger, "ImportAdaptiveMtFile")
1560 return err
1561 }, opts...)
1562 if err != nil {
1563 return nil, err
1564 }
1565 return resp, nil
1566 }
1567
1568 func (c *translationGRPCClient) ListAdaptiveMtFiles(ctx context.Context, req *translatepb.ListAdaptiveMtFilesRequest, opts ...gax.CallOption) *AdaptiveMtFileIterator {
1569 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1570
1571 hds = append(c.xGoogHeaders, hds...)
1572 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1573 opts = append((*c.CallOptions).ListAdaptiveMtFiles[0:len((*c.CallOptions).ListAdaptiveMtFiles):len((*c.CallOptions).ListAdaptiveMtFiles)], opts...)
1574 it := &AdaptiveMtFileIterator{}
1575 req = proto.Clone(req).(*translatepb.ListAdaptiveMtFilesRequest)
1576 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtFile, string, error) {
1577 resp := &translatepb.ListAdaptiveMtFilesResponse{}
1578 if pageToken != "" {
1579 req.PageToken = pageToken
1580 }
1581 if pageSize > math.MaxInt32 {
1582 req.PageSize = math.MaxInt32
1583 } else if pageSize != 0 {
1584 req.PageSize = int32(pageSize)
1585 }
1586 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1587 var err error
1588 resp, err = executeRPC(ctx, c.translationClient.ListAdaptiveMtFiles, req, settings.GRPC, c.logger, "ListAdaptiveMtFiles")
1589 return err
1590 }, opts...)
1591 if err != nil {
1592 return nil, "", err
1593 }
1594
1595 it.Response = resp
1596 return resp.GetAdaptiveMtFiles(), resp.GetNextPageToken(), nil
1597 }
1598 fetch := func(pageSize int, pageToken string) (string, error) {
1599 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1600 if err != nil {
1601 return "", err
1602 }
1603 it.items = append(it.items, items...)
1604 return nextPageToken, nil
1605 }
1606
1607 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1608 it.pageInfo.MaxSize = int(req.GetPageSize())
1609 it.pageInfo.Token = req.GetPageToken()
1610
1611 return it
1612 }
1613
1614 func (c *translationGRPCClient) ListAdaptiveMtSentences(ctx context.Context, req *translatepb.ListAdaptiveMtSentencesRequest, opts ...gax.CallOption) *AdaptiveMtSentenceIterator {
1615 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1616
1617 hds = append(c.xGoogHeaders, hds...)
1618 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1619 opts = append((*c.CallOptions).ListAdaptiveMtSentences[0:len((*c.CallOptions).ListAdaptiveMtSentences):len((*c.CallOptions).ListAdaptiveMtSentences)], opts...)
1620 it := &AdaptiveMtSentenceIterator{}
1621 req = proto.Clone(req).(*translatepb.ListAdaptiveMtSentencesRequest)
1622 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtSentence, string, error) {
1623 resp := &translatepb.ListAdaptiveMtSentencesResponse{}
1624 if pageToken != "" {
1625 req.PageToken = pageToken
1626 }
1627 if pageSize > math.MaxInt32 {
1628 req.PageSize = math.MaxInt32
1629 } else if pageSize != 0 {
1630 req.PageSize = int32(pageSize)
1631 }
1632 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1633 var err error
1634 resp, err = executeRPC(ctx, c.translationClient.ListAdaptiveMtSentences, req, settings.GRPC, c.logger, "ListAdaptiveMtSentences")
1635 return err
1636 }, opts...)
1637 if err != nil {
1638 return nil, "", err
1639 }
1640
1641 it.Response = resp
1642 return resp.GetAdaptiveMtSentences(), resp.GetNextPageToken(), nil
1643 }
1644 fetch := func(pageSize int, pageToken string) (string, error) {
1645 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1646 if err != nil {
1647 return "", err
1648 }
1649 it.items = append(it.items, items...)
1650 return nextPageToken, nil
1651 }
1652
1653 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1654 it.pageInfo.MaxSize = int(req.GetPageSize())
1655 it.pageInfo.Token = req.GetPageToken()
1656
1657 return it
1658 }
1659
1660 func (c *translationGRPCClient) ImportData(ctx context.Context, req *translatepb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) {
1661 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset", url.QueryEscape(req.GetDataset()))}
1662
1663 hds = append(c.xGoogHeaders, hds...)
1664 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1665 opts = append((*c.CallOptions).ImportData[0:len((*c.CallOptions).ImportData):len((*c.CallOptions).ImportData)], opts...)
1666 var resp *longrunningpb.Operation
1667 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1668 var err error
1669 resp, err = executeRPC(ctx, c.translationClient.ImportData, req, settings.GRPC, c.logger, "ImportData")
1670 return err
1671 }, opts...)
1672 if err != nil {
1673 return nil, err
1674 }
1675 return &ImportDataOperation{
1676 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1677 }, nil
1678 }
1679
1680 func (c *translationGRPCClient) ExportData(ctx context.Context, req *translatepb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) {
1681 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset", url.QueryEscape(req.GetDataset()))}
1682
1683 hds = append(c.xGoogHeaders, hds...)
1684 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1685 opts = append((*c.CallOptions).ExportData[0:len((*c.CallOptions).ExportData):len((*c.CallOptions).ExportData)], opts...)
1686 var resp *longrunningpb.Operation
1687 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1688 var err error
1689 resp, err = executeRPC(ctx, c.translationClient.ExportData, req, settings.GRPC, c.logger, "ExportData")
1690 return err
1691 }, opts...)
1692 if err != nil {
1693 return nil, err
1694 }
1695 return &ExportDataOperation{
1696 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1697 }, nil
1698 }
1699
1700 func (c *translationGRPCClient) ListExamples(ctx context.Context, req *translatepb.ListExamplesRequest, opts ...gax.CallOption) *ExampleIterator {
1701 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1702
1703 hds = append(c.xGoogHeaders, hds...)
1704 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1705 opts = append((*c.CallOptions).ListExamples[0:len((*c.CallOptions).ListExamples):len((*c.CallOptions).ListExamples)], opts...)
1706 it := &ExampleIterator{}
1707 req = proto.Clone(req).(*translatepb.ListExamplesRequest)
1708 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Example, string, error) {
1709 resp := &translatepb.ListExamplesResponse{}
1710 if pageToken != "" {
1711 req.PageToken = pageToken
1712 }
1713 if pageSize > math.MaxInt32 {
1714 req.PageSize = math.MaxInt32
1715 } else if pageSize != 0 {
1716 req.PageSize = int32(pageSize)
1717 }
1718 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1719 var err error
1720 resp, err = executeRPC(ctx, c.translationClient.ListExamples, req, settings.GRPC, c.logger, "ListExamples")
1721 return err
1722 }, opts...)
1723 if err != nil {
1724 return nil, "", err
1725 }
1726
1727 it.Response = resp
1728 return resp.GetExamples(), resp.GetNextPageToken(), nil
1729 }
1730 fetch := func(pageSize int, pageToken string) (string, error) {
1731 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1732 if err != nil {
1733 return "", err
1734 }
1735 it.items = append(it.items, items...)
1736 return nextPageToken, nil
1737 }
1738
1739 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1740 it.pageInfo.MaxSize = int(req.GetPageSize())
1741 it.pageInfo.Token = req.GetPageToken()
1742
1743 return it
1744 }
1745
1746 func (c *translationGRPCClient) CreateModel(ctx context.Context, req *translatepb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) {
1747 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1748
1749 hds = append(c.xGoogHeaders, hds...)
1750 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1751 opts = append((*c.CallOptions).CreateModel[0:len((*c.CallOptions).CreateModel):len((*c.CallOptions).CreateModel)], opts...)
1752 var resp *longrunningpb.Operation
1753 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1754 var err error
1755 resp, err = executeRPC(ctx, c.translationClient.CreateModel, req, settings.GRPC, c.logger, "CreateModel")
1756 return err
1757 }, opts...)
1758 if err != nil {
1759 return nil, err
1760 }
1761 return &CreateModelOperation{
1762 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1763 }, nil
1764 }
1765
1766 func (c *translationGRPCClient) ListModels(ctx context.Context, req *translatepb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator {
1767 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1768
1769 hds = append(c.xGoogHeaders, hds...)
1770 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1771 opts = append((*c.CallOptions).ListModels[0:len((*c.CallOptions).ListModels):len((*c.CallOptions).ListModels)], opts...)
1772 it := &ModelIterator{}
1773 req = proto.Clone(req).(*translatepb.ListModelsRequest)
1774 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Model, string, error) {
1775 resp := &translatepb.ListModelsResponse{}
1776 if pageToken != "" {
1777 req.PageToken = pageToken
1778 }
1779 if pageSize > math.MaxInt32 {
1780 req.PageSize = math.MaxInt32
1781 } else if pageSize != 0 {
1782 req.PageSize = int32(pageSize)
1783 }
1784 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1785 var err error
1786 resp, err = executeRPC(ctx, c.translationClient.ListModels, req, settings.GRPC, c.logger, "ListModels")
1787 return err
1788 }, opts...)
1789 if err != nil {
1790 return nil, "", err
1791 }
1792
1793 it.Response = resp
1794 return resp.GetModels(), resp.GetNextPageToken(), nil
1795 }
1796 fetch := func(pageSize int, pageToken string) (string, error) {
1797 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1798 if err != nil {
1799 return "", err
1800 }
1801 it.items = append(it.items, items...)
1802 return nextPageToken, nil
1803 }
1804
1805 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1806 it.pageInfo.MaxSize = int(req.GetPageSize())
1807 it.pageInfo.Token = req.GetPageToken()
1808
1809 return it
1810 }
1811
1812 func (c *translationGRPCClient) GetModel(ctx context.Context, req *translatepb.GetModelRequest, opts ...gax.CallOption) (*translatepb.Model, error) {
1813 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1814
1815 hds = append(c.xGoogHeaders, hds...)
1816 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1817 opts = append((*c.CallOptions).GetModel[0:len((*c.CallOptions).GetModel):len((*c.CallOptions).GetModel)], opts...)
1818 var resp *translatepb.Model
1819 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1820 var err error
1821 resp, err = executeRPC(ctx, c.translationClient.GetModel, req, settings.GRPC, c.logger, "GetModel")
1822 return err
1823 }, opts...)
1824 if err != nil {
1825 return nil, err
1826 }
1827 return resp, nil
1828 }
1829
1830 func (c *translationGRPCClient) DeleteModel(ctx context.Context, req *translatepb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) {
1831 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1832
1833 hds = append(c.xGoogHeaders, hds...)
1834 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1835 opts = append((*c.CallOptions).DeleteModel[0:len((*c.CallOptions).DeleteModel):len((*c.CallOptions).DeleteModel)], opts...)
1836 var resp *longrunningpb.Operation
1837 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1838 var err error
1839 resp, err = executeRPC(ctx, c.translationClient.DeleteModel, req, settings.GRPC, c.logger, "DeleteModel")
1840 return err
1841 }, opts...)
1842 if err != nil {
1843 return nil, err
1844 }
1845 return &DeleteModelOperation{
1846 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1847 }, nil
1848 }
1849
1850 func (c *translationGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
1851 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1852
1853 hds = append(c.xGoogHeaders, hds...)
1854 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1855 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
1856 var resp *locationpb.Location
1857 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1858 var err error
1859 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
1860 return err
1861 }, opts...)
1862 if err != nil {
1863 return nil, err
1864 }
1865 return resp, nil
1866 }
1867
1868 func (c *translationGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
1869 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1870
1871 hds = append(c.xGoogHeaders, hds...)
1872 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1873 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
1874 it := &LocationIterator{}
1875 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
1876 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
1877 resp := &locationpb.ListLocationsResponse{}
1878 if pageToken != "" {
1879 req.PageToken = pageToken
1880 }
1881 if pageSize > math.MaxInt32 {
1882 req.PageSize = math.MaxInt32
1883 } else if pageSize != 0 {
1884 req.PageSize = int32(pageSize)
1885 }
1886 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1887 var err error
1888 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
1889 return err
1890 }, opts...)
1891 if err != nil {
1892 return nil, "", err
1893 }
1894
1895 it.Response = resp
1896 return resp.GetLocations(), resp.GetNextPageToken(), nil
1897 }
1898 fetch := func(pageSize int, pageToken string) (string, error) {
1899 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1900 if err != nil {
1901 return "", err
1902 }
1903 it.items = append(it.items, items...)
1904 return nextPageToken, nil
1905 }
1906
1907 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1908 it.pageInfo.MaxSize = int(req.GetPageSize())
1909 it.pageInfo.Token = req.GetPageToken()
1910
1911 return it
1912 }
1913
1914 func (c *translationGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
1915 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1916
1917 hds = append(c.xGoogHeaders, hds...)
1918 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1919 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
1920 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1921 var err error
1922 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
1923 return err
1924 }, opts...)
1925 return err
1926 }
1927
1928 func (c *translationGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
1929 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1930
1931 hds = append(c.xGoogHeaders, hds...)
1932 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1933 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
1934 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1935 var err error
1936 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
1937 return err
1938 }, opts...)
1939 return err
1940 }
1941
1942 func (c *translationGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1943 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1944
1945 hds = append(c.xGoogHeaders, hds...)
1946 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1947 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1948 var resp *longrunningpb.Operation
1949 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1950 var err error
1951 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
1952 return err
1953 }, opts...)
1954 if err != nil {
1955 return nil, err
1956 }
1957 return resp, nil
1958 }
1959
1960 func (c *translationGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
1961 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1962
1963 hds = append(c.xGoogHeaders, hds...)
1964 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1965 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
1966 it := &OperationIterator{}
1967 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
1968 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
1969 resp := &longrunningpb.ListOperationsResponse{}
1970 if pageToken != "" {
1971 req.PageToken = pageToken
1972 }
1973 if pageSize > math.MaxInt32 {
1974 req.PageSize = math.MaxInt32
1975 } else if pageSize != 0 {
1976 req.PageSize = int32(pageSize)
1977 }
1978 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1979 var err error
1980 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
1981 return err
1982 }, opts...)
1983 if err != nil {
1984 return nil, "", err
1985 }
1986
1987 it.Response = resp
1988 return resp.GetOperations(), resp.GetNextPageToken(), nil
1989 }
1990 fetch := func(pageSize int, pageToken string) (string, error) {
1991 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1992 if err != nil {
1993 return "", err
1994 }
1995 it.items = append(it.items, items...)
1996 return nextPageToken, nil
1997 }
1998
1999 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2000 it.pageInfo.MaxSize = int(req.GetPageSize())
2001 it.pageInfo.Token = req.GetPageToken()
2002
2003 return it
2004 }
2005
2006 func (c *translationGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
2007 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2008
2009 hds = append(c.xGoogHeaders, hds...)
2010 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
2011 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
2012 var resp *longrunningpb.Operation
2013 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2014 var err error
2015 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
2016 return err
2017 }, opts...)
2018 if err != nil {
2019 return nil, err
2020 }
2021 return resp, nil
2022 }
2023
2024 // TranslateText translates input text and returns translated text.
2025 func (c *translationRESTClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, opts ...gax.CallOption) (*translatepb.TranslateTextResponse, error) {
2026 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2027 jsonReq, err := m.Marshal(req)
2028 if err != nil {
2029 return nil, err
2030 }
2031
2032 baseUrl, err := url.Parse(c.endpoint)
2033 if err != nil {
2034 return nil, err
2035 }
2036 baseUrl.Path += fmt.Sprintf("/v3/%v:translateText", req.GetParent())
2037
2038 params := url.Values{}
2039 params.Add("$alt", "json;enum-encoding=int")
2040
2041 baseUrl.RawQuery = params.Encode()
2042
2043 // Build HTTP headers from client and context metadata.
2044 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2045
2046 hds = append(c.xGoogHeaders, hds...)
2047 hds = append(hds, "Content-Type", "application/json")
2048 headers := gax.BuildHeaders(ctx, hds...)
2049 opts = append((*c.CallOptions).TranslateText[0:len((*c.CallOptions).TranslateText):len((*c.CallOptions).TranslateText)], opts...)
2050 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2051 resp := &translatepb.TranslateTextResponse{}
2052 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2053 if settings.Path != "" {
2054 baseUrl.Path = settings.Path
2055 }
2056 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2057 if err != nil {
2058 return err
2059 }
2060 httpReq = httpReq.WithContext(ctx)
2061 httpReq.Header = headers
2062
2063 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TranslateText")
2064 if err != nil {
2065 return err
2066 }
2067
2068 if err := unm.Unmarshal(buf, resp); err != nil {
2069 return err
2070 }
2071
2072 return nil
2073 }, opts...)
2074 if e != nil {
2075 return nil, e
2076 }
2077 return resp, nil
2078 }
2079
2080 // RomanizeText romanize input text written in non-Latin scripts to Latin text.
2081 func (c *translationRESTClient) RomanizeText(ctx context.Context, req *translatepb.RomanizeTextRequest, opts ...gax.CallOption) (*translatepb.RomanizeTextResponse, error) {
2082 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2083 jsonReq, err := m.Marshal(req)
2084 if err != nil {
2085 return nil, err
2086 }
2087
2088 baseUrl, err := url.Parse(c.endpoint)
2089 if err != nil {
2090 return nil, err
2091 }
2092 baseUrl.Path += fmt.Sprintf("/v3/%v:romanizeText", req.GetParent())
2093
2094 params := url.Values{}
2095 params.Add("$alt", "json;enum-encoding=int")
2096
2097 baseUrl.RawQuery = params.Encode()
2098
2099 // Build HTTP headers from client and context metadata.
2100 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2101
2102 hds = append(c.xGoogHeaders, hds...)
2103 hds = append(hds, "Content-Type", "application/json")
2104 headers := gax.BuildHeaders(ctx, hds...)
2105 opts = append((*c.CallOptions).RomanizeText[0:len((*c.CallOptions).RomanizeText):len((*c.CallOptions).RomanizeText)], opts...)
2106 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2107 resp := &translatepb.RomanizeTextResponse{}
2108 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2109 if settings.Path != "" {
2110 baseUrl.Path = settings.Path
2111 }
2112 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2113 if err != nil {
2114 return err
2115 }
2116 httpReq = httpReq.WithContext(ctx)
2117 httpReq.Header = headers
2118
2119 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RomanizeText")
2120 if err != nil {
2121 return err
2122 }
2123
2124 if err := unm.Unmarshal(buf, resp); err != nil {
2125 return err
2126 }
2127
2128 return nil
2129 }, opts...)
2130 if e != nil {
2131 return nil, e
2132 }
2133 return resp, nil
2134 }
2135
2136 // DetectLanguage detects the language of text within a request.
2137 func (c *translationRESTClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, opts ...gax.CallOption) (*translatepb.DetectLanguageResponse, error) {
2138 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2139 jsonReq, err := m.Marshal(req)
2140 if err != nil {
2141 return nil, err
2142 }
2143
2144 baseUrl, err := url.Parse(c.endpoint)
2145 if err != nil {
2146 return nil, err
2147 }
2148 baseUrl.Path += fmt.Sprintf("/v3/%v:detectLanguage", req.GetParent())
2149
2150 params := url.Values{}
2151 params.Add("$alt", "json;enum-encoding=int")
2152
2153 baseUrl.RawQuery = params.Encode()
2154
2155 // Build HTTP headers from client and context metadata.
2156 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2157
2158 hds = append(c.xGoogHeaders, hds...)
2159 hds = append(hds, "Content-Type", "application/json")
2160 headers := gax.BuildHeaders(ctx, hds...)
2161 opts = append((*c.CallOptions).DetectLanguage[0:len((*c.CallOptions).DetectLanguage):len((*c.CallOptions).DetectLanguage)], opts...)
2162 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2163 resp := &translatepb.DetectLanguageResponse{}
2164 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2165 if settings.Path != "" {
2166 baseUrl.Path = settings.Path
2167 }
2168 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2169 if err != nil {
2170 return err
2171 }
2172 httpReq = httpReq.WithContext(ctx)
2173 httpReq.Header = headers
2174
2175 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "DetectLanguage")
2176 if err != nil {
2177 return err
2178 }
2179
2180 if err := unm.Unmarshal(buf, resp); err != nil {
2181 return err
2182 }
2183
2184 return nil
2185 }, opts...)
2186 if e != nil {
2187 return nil, e
2188 }
2189 return resp, nil
2190 }
2191
2192 // GetSupportedLanguages returns a list of supported languages for translation.
2193 func (c *translationRESTClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, opts ...gax.CallOption) (*translatepb.SupportedLanguages, error) {
2194 baseUrl, err := url.Parse(c.endpoint)
2195 if err != nil {
2196 return nil, err
2197 }
2198 baseUrl.Path += fmt.Sprintf("/v3/%v/supportedLanguages", req.GetParent())
2199
2200 params := url.Values{}
2201 params.Add("$alt", "json;enum-encoding=int")
2202 if req.GetDisplayLanguageCode() != "" {
2203 params.Add("displayLanguageCode", fmt.Sprintf("%v", req.GetDisplayLanguageCode()))
2204 }
2205 if req.GetModel() != "" {
2206 params.Add("model", fmt.Sprintf("%v", req.GetModel()))
2207 }
2208
2209 baseUrl.RawQuery = params.Encode()
2210
2211 // Build HTTP headers from client and context metadata.
2212 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2213
2214 hds = append(c.xGoogHeaders, hds...)
2215 hds = append(hds, "Content-Type", "application/json")
2216 headers := gax.BuildHeaders(ctx, hds...)
2217 opts = append((*c.CallOptions).GetSupportedLanguages[0:len((*c.CallOptions).GetSupportedLanguages):len((*c.CallOptions).GetSupportedLanguages)], opts...)
2218 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2219 resp := &translatepb.SupportedLanguages{}
2220 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2221 if settings.Path != "" {
2222 baseUrl.Path = settings.Path
2223 }
2224 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2225 if err != nil {
2226 return err
2227 }
2228 httpReq = httpReq.WithContext(ctx)
2229 httpReq.Header = headers
2230
2231 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSupportedLanguages")
2232 if err != nil {
2233 return err
2234 }
2235
2236 if err := unm.Unmarshal(buf, resp); err != nil {
2237 return err
2238 }
2239
2240 return nil
2241 }, opts...)
2242 if e != nil {
2243 return nil, e
2244 }
2245 return resp, nil
2246 }
2247
2248 // TranslateDocument translates documents in synchronous mode.
2249 func (c *translationRESTClient) TranslateDocument(ctx context.Context, req *translatepb.TranslateDocumentRequest, opts ...gax.CallOption) (*translatepb.TranslateDocumentResponse, error) {
2250 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2251 jsonReq, err := m.Marshal(req)
2252 if err != nil {
2253 return nil, err
2254 }
2255
2256 baseUrl, err := url.Parse(c.endpoint)
2257 if err != nil {
2258 return nil, err
2259 }
2260 baseUrl.Path += fmt.Sprintf("/v3/%v:translateDocument", req.GetParent())
2261
2262 params := url.Values{}
2263 params.Add("$alt", "json;enum-encoding=int")
2264
2265 baseUrl.RawQuery = params.Encode()
2266
2267 // Build HTTP headers from client and context metadata.
2268 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2269
2270 hds = append(c.xGoogHeaders, hds...)
2271 hds = append(hds, "Content-Type", "application/json")
2272 headers := gax.BuildHeaders(ctx, hds...)
2273 opts = append((*c.CallOptions).TranslateDocument[0:len((*c.CallOptions).TranslateDocument):len((*c.CallOptions).TranslateDocument)], opts...)
2274 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2275 resp := &translatepb.TranslateDocumentResponse{}
2276 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2277 if settings.Path != "" {
2278 baseUrl.Path = settings.Path
2279 }
2280 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2281 if err != nil {
2282 return err
2283 }
2284 httpReq = httpReq.WithContext(ctx)
2285 httpReq.Header = headers
2286
2287 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TranslateDocument")
2288 if err != nil {
2289 return err
2290 }
2291
2292 if err := unm.Unmarshal(buf, resp); err != nil {
2293 return err
2294 }
2295
2296 return nil
2297 }, opts...)
2298 if e != nil {
2299 return nil, e
2300 }
2301 return resp, nil
2302 }
2303
2304 // BatchTranslateText translates a large volume of text in asynchronous batch mode.
2305 // This function provides real-time output as the inputs are being processed.
2306 // If caller cancels a request, the partial results (for an input file, it’s
2307 // all or nothing) may still be available on the specified output location.
2308 //
2309 // This call returns immediately and you can
2310 // use google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call.
2311 func (c *translationRESTClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, opts ...gax.CallOption) (*BatchTranslateTextOperation, error) {
2312 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2313 jsonReq, err := m.Marshal(req)
2314 if err != nil {
2315 return nil, err
2316 }
2317
2318 baseUrl, err := url.Parse(c.endpoint)
2319 if err != nil {
2320 return nil, err
2321 }
2322 baseUrl.Path += fmt.Sprintf("/v3/%v:batchTranslateText", req.GetParent())
2323
2324 params := url.Values{}
2325 params.Add("$alt", "json;enum-encoding=int")
2326
2327 baseUrl.RawQuery = params.Encode()
2328
2329 // Build HTTP headers from client and context metadata.
2330 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2331
2332 hds = append(c.xGoogHeaders, hds...)
2333 hds = append(hds, "Content-Type", "application/json")
2334 headers := gax.BuildHeaders(ctx, hds...)
2335 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2336 resp := &longrunningpb.Operation{}
2337 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2338 if settings.Path != "" {
2339 baseUrl.Path = settings.Path
2340 }
2341 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2342 if err != nil {
2343 return err
2344 }
2345 httpReq = httpReq.WithContext(ctx)
2346 httpReq.Header = headers
2347
2348 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchTranslateText")
2349 if err != nil {
2350 return err
2351 }
2352 if err := unm.Unmarshal(buf, resp); err != nil {
2353 return err
2354 }
2355
2356 return nil
2357 }, opts...)
2358 if e != nil {
2359 return nil, e
2360 }
2361
2362 override := fmt.Sprintf("/v3/%s", resp.GetName())
2363 return &BatchTranslateTextOperation{
2364 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2365 pollPath: override,
2366 }, nil
2367 }
2368
2369 // BatchTranslateDocument translates a large volume of document in asynchronous batch mode.
2370 // This function provides real-time output as the inputs are being processed.
2371 // If caller cancels a request, the partial results (for an input file, it’s
2372 // all or nothing) may still be available on the specified output location.
2373 //
2374 // This call returns immediately and you can use
2375 // google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call.
2376 func (c *translationRESTClient) BatchTranslateDocument(ctx context.Context, req *translatepb.BatchTranslateDocumentRequest, opts ...gax.CallOption) (*BatchTranslateDocumentOperation, error) {
2377 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2378 jsonReq, err := m.Marshal(req)
2379 if err != nil {
2380 return nil, err
2381 }
2382
2383 baseUrl, err := url.Parse(c.endpoint)
2384 if err != nil {
2385 return nil, err
2386 }
2387 baseUrl.Path += fmt.Sprintf("/v3/%v:batchTranslateDocument", req.GetParent())
2388
2389 params := url.Values{}
2390 params.Add("$alt", "json;enum-encoding=int")
2391
2392 baseUrl.RawQuery = params.Encode()
2393
2394 // Build HTTP headers from client and context metadata.
2395 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2396
2397 hds = append(c.xGoogHeaders, hds...)
2398 hds = append(hds, "Content-Type", "application/json")
2399 headers := gax.BuildHeaders(ctx, hds...)
2400 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2401 resp := &longrunningpb.Operation{}
2402 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2403 if settings.Path != "" {
2404 baseUrl.Path = settings.Path
2405 }
2406 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2407 if err != nil {
2408 return err
2409 }
2410 httpReq = httpReq.WithContext(ctx)
2411 httpReq.Header = headers
2412
2413 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchTranslateDocument")
2414 if err != nil {
2415 return err
2416 }
2417 if err := unm.Unmarshal(buf, resp); err != nil {
2418 return err
2419 }
2420
2421 return nil
2422 }, opts...)
2423 if e != nil {
2424 return nil, e
2425 }
2426
2427 override := fmt.Sprintf("/v3/%s", resp.GetName())
2428 return &BatchTranslateDocumentOperation{
2429 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2430 pollPath: override,
2431 }, nil
2432 }
2433
2434 // CreateGlossary creates a glossary and returns the long-running operation. Returns
2435 // NOT_FOUND, if the project doesn’t exist.
2436 func (c *translationRESTClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, opts ...gax.CallOption) (*CreateGlossaryOperation, error) {
2437 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2438 body := req.GetGlossary()
2439 jsonReq, err := m.Marshal(body)
2440 if err != nil {
2441 return nil, err
2442 }
2443
2444 baseUrl, err := url.Parse(c.endpoint)
2445 if err != nil {
2446 return nil, err
2447 }
2448 baseUrl.Path += fmt.Sprintf("/v3/%v/glossaries", req.GetParent())
2449
2450 params := url.Values{}
2451 params.Add("$alt", "json;enum-encoding=int")
2452
2453 baseUrl.RawQuery = params.Encode()
2454
2455 // Build HTTP headers from client and context metadata.
2456 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2457
2458 hds = append(c.xGoogHeaders, hds...)
2459 hds = append(hds, "Content-Type", "application/json")
2460 headers := gax.BuildHeaders(ctx, hds...)
2461 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2462 resp := &longrunningpb.Operation{}
2463 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2464 if settings.Path != "" {
2465 baseUrl.Path = settings.Path
2466 }
2467 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2468 if err != nil {
2469 return err
2470 }
2471 httpReq = httpReq.WithContext(ctx)
2472 httpReq.Header = headers
2473
2474 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateGlossary")
2475 if err != nil {
2476 return err
2477 }
2478 if err := unm.Unmarshal(buf, resp); err != nil {
2479 return err
2480 }
2481
2482 return nil
2483 }, opts...)
2484 if e != nil {
2485 return nil, e
2486 }
2487
2488 override := fmt.Sprintf("/v3/%s", resp.GetName())
2489 return &CreateGlossaryOperation{
2490 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2491 pollPath: override,
2492 }, nil
2493 }
2494
2495 // UpdateGlossary updates a glossary. A LRO is used since the update can be async if the
2496 // glossary’s entry file is updated.
2497 func (c *translationRESTClient) UpdateGlossary(ctx context.Context, req *translatepb.UpdateGlossaryRequest, opts ...gax.CallOption) (*UpdateGlossaryOperation, error) {
2498 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2499 body := req.GetGlossary()
2500 jsonReq, err := m.Marshal(body)
2501 if err != nil {
2502 return nil, err
2503 }
2504
2505 baseUrl, err := url.Parse(c.endpoint)
2506 if err != nil {
2507 return nil, err
2508 }
2509 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetGlossary().GetName())
2510
2511 params := url.Values{}
2512 params.Add("$alt", "json;enum-encoding=int")
2513 if req.GetUpdateMask() != nil {
2514 field, err := protojson.Marshal(req.GetUpdateMask())
2515 if err != nil {
2516 return nil, err
2517 }
2518 params.Add("updateMask", string(field[1:len(field)-1]))
2519 }
2520
2521 baseUrl.RawQuery = params.Encode()
2522
2523 // Build HTTP headers from client and context metadata.
2524 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "glossary.name", url.QueryEscape(req.GetGlossary().GetName()))}
2525
2526 hds = append(c.xGoogHeaders, hds...)
2527 hds = append(hds, "Content-Type", "application/json")
2528 headers := gax.BuildHeaders(ctx, hds...)
2529 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2530 resp := &longrunningpb.Operation{}
2531 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2532 if settings.Path != "" {
2533 baseUrl.Path = settings.Path
2534 }
2535 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2536 if err != nil {
2537 return err
2538 }
2539 httpReq = httpReq.WithContext(ctx)
2540 httpReq.Header = headers
2541
2542 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateGlossary")
2543 if err != nil {
2544 return err
2545 }
2546 if err := unm.Unmarshal(buf, resp); err != nil {
2547 return err
2548 }
2549
2550 return nil
2551 }, opts...)
2552 if e != nil {
2553 return nil, e
2554 }
2555
2556 override := fmt.Sprintf("/v3/%s", resp.GetName())
2557 return &UpdateGlossaryOperation{
2558 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2559 pollPath: override,
2560 }, nil
2561 }
2562
2563 // ListGlossaries lists glossaries in a project. Returns NOT_FOUND, if the project doesn’t
2564 // exist.
2565 func (c *translationRESTClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, opts ...gax.CallOption) *GlossaryIterator {
2566 it := &GlossaryIterator{}
2567 req = proto.Clone(req).(*translatepb.ListGlossariesRequest)
2568 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2569 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Glossary, string, error) {
2570 resp := &translatepb.ListGlossariesResponse{}
2571 if pageToken != "" {
2572 req.PageToken = pageToken
2573 }
2574 if pageSize > math.MaxInt32 {
2575 req.PageSize = math.MaxInt32
2576 } else if pageSize != 0 {
2577 req.PageSize = int32(pageSize)
2578 }
2579 baseUrl, err := url.Parse(c.endpoint)
2580 if err != nil {
2581 return nil, "", err
2582 }
2583 baseUrl.Path += fmt.Sprintf("/v3/%v/glossaries", req.GetParent())
2584
2585 params := url.Values{}
2586 params.Add("$alt", "json;enum-encoding=int")
2587 if req.GetFilter() != "" {
2588 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2589 }
2590 if req.GetPageSize() != 0 {
2591 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2592 }
2593 if req.GetPageToken() != "" {
2594 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2595 }
2596
2597 baseUrl.RawQuery = params.Encode()
2598
2599 // Build HTTP headers from client and context metadata.
2600 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2601 headers := gax.BuildHeaders(ctx, hds...)
2602 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2603 if settings.Path != "" {
2604 baseUrl.Path = settings.Path
2605 }
2606 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2607 if err != nil {
2608 return err
2609 }
2610 httpReq.Header = headers
2611
2612 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListGlossaries")
2613 if err != nil {
2614 return err
2615 }
2616 if err := unm.Unmarshal(buf, resp); err != nil {
2617 return err
2618 }
2619
2620 return nil
2621 }, opts...)
2622 if e != nil {
2623 return nil, "", e
2624 }
2625 it.Response = resp
2626 return resp.GetGlossaries(), resp.GetNextPageToken(), nil
2627 }
2628
2629 fetch := func(pageSize int, pageToken string) (string, error) {
2630 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2631 if err != nil {
2632 return "", err
2633 }
2634 it.items = append(it.items, items...)
2635 return nextPageToken, nil
2636 }
2637
2638 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2639 it.pageInfo.MaxSize = int(req.GetPageSize())
2640 it.pageInfo.Token = req.GetPageToken()
2641
2642 return it
2643 }
2644
2645 // GetGlossary gets a glossary. Returns NOT_FOUND, if the glossary doesn’t
2646 // exist.
2647 func (c *translationRESTClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, opts ...gax.CallOption) (*translatepb.Glossary, error) {
2648 baseUrl, err := url.Parse(c.endpoint)
2649 if err != nil {
2650 return nil, err
2651 }
2652 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
2653
2654 params := url.Values{}
2655 params.Add("$alt", "json;enum-encoding=int")
2656
2657 baseUrl.RawQuery = params.Encode()
2658
2659 // Build HTTP headers from client and context metadata.
2660 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2661
2662 hds = append(c.xGoogHeaders, hds...)
2663 hds = append(hds, "Content-Type", "application/json")
2664 headers := gax.BuildHeaders(ctx, hds...)
2665 opts = append((*c.CallOptions).GetGlossary[0:len((*c.CallOptions).GetGlossary):len((*c.CallOptions).GetGlossary)], opts...)
2666 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2667 resp := &translatepb.Glossary{}
2668 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2669 if settings.Path != "" {
2670 baseUrl.Path = settings.Path
2671 }
2672 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2673 if err != nil {
2674 return err
2675 }
2676 httpReq = httpReq.WithContext(ctx)
2677 httpReq.Header = headers
2678
2679 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetGlossary")
2680 if err != nil {
2681 return err
2682 }
2683
2684 if err := unm.Unmarshal(buf, resp); err != nil {
2685 return err
2686 }
2687
2688 return nil
2689 }, opts...)
2690 if e != nil {
2691 return nil, e
2692 }
2693 return resp, nil
2694 }
2695
2696 // DeleteGlossary deletes a glossary, or cancels glossary construction
2697 // if the glossary isn’t created yet.
2698 // Returns NOT_FOUND, if the glossary doesn’t exist.
2699 func (c *translationRESTClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, opts ...gax.CallOption) (*DeleteGlossaryOperation, error) {
2700 baseUrl, err := url.Parse(c.endpoint)
2701 if err != nil {
2702 return nil, err
2703 }
2704 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
2705
2706 params := url.Values{}
2707 params.Add("$alt", "json;enum-encoding=int")
2708
2709 baseUrl.RawQuery = params.Encode()
2710
2711 // Build HTTP headers from client and context metadata.
2712 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2713
2714 hds = append(c.xGoogHeaders, hds...)
2715 hds = append(hds, "Content-Type", "application/json")
2716 headers := gax.BuildHeaders(ctx, hds...)
2717 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2718 resp := &longrunningpb.Operation{}
2719 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2720 if settings.Path != "" {
2721 baseUrl.Path = settings.Path
2722 }
2723 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2724 if err != nil {
2725 return err
2726 }
2727 httpReq = httpReq.WithContext(ctx)
2728 httpReq.Header = headers
2729
2730 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteGlossary")
2731 if err != nil {
2732 return err
2733 }
2734 if err := unm.Unmarshal(buf, resp); err != nil {
2735 return err
2736 }
2737
2738 return nil
2739 }, opts...)
2740 if e != nil {
2741 return nil, e
2742 }
2743
2744 override := fmt.Sprintf("/v3/%s", resp.GetName())
2745 return &DeleteGlossaryOperation{
2746 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2747 pollPath: override,
2748 }, nil
2749 }
2750
2751 // GetGlossaryEntry gets a single glossary entry by the given id.
2752 func (c *translationRESTClient) GetGlossaryEntry(ctx context.Context, req *translatepb.GetGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
2753 baseUrl, err := url.Parse(c.endpoint)
2754 if err != nil {
2755 return nil, err
2756 }
2757 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
2758
2759 params := url.Values{}
2760 params.Add("$alt", "json;enum-encoding=int")
2761
2762 baseUrl.RawQuery = params.Encode()
2763
2764 // Build HTTP headers from client and context metadata.
2765 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2766
2767 hds = append(c.xGoogHeaders, hds...)
2768 hds = append(hds, "Content-Type", "application/json")
2769 headers := gax.BuildHeaders(ctx, hds...)
2770 opts = append((*c.CallOptions).GetGlossaryEntry[0:len((*c.CallOptions).GetGlossaryEntry):len((*c.CallOptions).GetGlossaryEntry)], opts...)
2771 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2772 resp := &translatepb.GlossaryEntry{}
2773 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2774 if settings.Path != "" {
2775 baseUrl.Path = settings.Path
2776 }
2777 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2778 if err != nil {
2779 return err
2780 }
2781 httpReq = httpReq.WithContext(ctx)
2782 httpReq.Header = headers
2783
2784 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetGlossaryEntry")
2785 if err != nil {
2786 return err
2787 }
2788
2789 if err := unm.Unmarshal(buf, resp); err != nil {
2790 return err
2791 }
2792
2793 return nil
2794 }, opts...)
2795 if e != nil {
2796 return nil, e
2797 }
2798 return resp, nil
2799 }
2800
2801 // ListGlossaryEntries list the entries for the glossary.
2802 func (c *translationRESTClient) ListGlossaryEntries(ctx context.Context, req *translatepb.ListGlossaryEntriesRequest, opts ...gax.CallOption) *GlossaryEntryIterator {
2803 it := &GlossaryEntryIterator{}
2804 req = proto.Clone(req).(*translatepb.ListGlossaryEntriesRequest)
2805 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2806 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.GlossaryEntry, string, error) {
2807 resp := &translatepb.ListGlossaryEntriesResponse{}
2808 if pageToken != "" {
2809 req.PageToken = pageToken
2810 }
2811 if pageSize > math.MaxInt32 {
2812 req.PageSize = math.MaxInt32
2813 } else if pageSize != 0 {
2814 req.PageSize = int32(pageSize)
2815 }
2816 baseUrl, err := url.Parse(c.endpoint)
2817 if err != nil {
2818 return nil, "", err
2819 }
2820 baseUrl.Path += fmt.Sprintf("/v3/%v/glossaryEntries", req.GetParent())
2821
2822 params := url.Values{}
2823 params.Add("$alt", "json;enum-encoding=int")
2824 if req.GetPageSize() != 0 {
2825 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2826 }
2827 if req.GetPageToken() != "" {
2828 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2829 }
2830
2831 baseUrl.RawQuery = params.Encode()
2832
2833 // Build HTTP headers from client and context metadata.
2834 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2835 headers := gax.BuildHeaders(ctx, hds...)
2836 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2837 if settings.Path != "" {
2838 baseUrl.Path = settings.Path
2839 }
2840 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2841 if err != nil {
2842 return err
2843 }
2844 httpReq.Header = headers
2845
2846 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListGlossaryEntries")
2847 if err != nil {
2848 return err
2849 }
2850 if err := unm.Unmarshal(buf, resp); err != nil {
2851 return err
2852 }
2853
2854 return nil
2855 }, opts...)
2856 if e != nil {
2857 return nil, "", e
2858 }
2859 it.Response = resp
2860 return resp.GetGlossaryEntries(), resp.GetNextPageToken(), nil
2861 }
2862
2863 fetch := func(pageSize int, pageToken string) (string, error) {
2864 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2865 if err != nil {
2866 return "", err
2867 }
2868 it.items = append(it.items, items...)
2869 return nextPageToken, nil
2870 }
2871
2872 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2873 it.pageInfo.MaxSize = int(req.GetPageSize())
2874 it.pageInfo.Token = req.GetPageToken()
2875
2876 return it
2877 }
2878
2879 // CreateGlossaryEntry creates a glossary entry.
2880 func (c *translationRESTClient) CreateGlossaryEntry(ctx context.Context, req *translatepb.CreateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
2881 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2882 body := req.GetGlossaryEntry()
2883 jsonReq, err := m.Marshal(body)
2884 if err != nil {
2885 return nil, err
2886 }
2887
2888 baseUrl, err := url.Parse(c.endpoint)
2889 if err != nil {
2890 return nil, err
2891 }
2892 baseUrl.Path += fmt.Sprintf("/v3/%v/glossaryEntries", req.GetParent())
2893
2894 params := url.Values{}
2895 params.Add("$alt", "json;enum-encoding=int")
2896
2897 baseUrl.RawQuery = params.Encode()
2898
2899 // Build HTTP headers from client and context metadata.
2900 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2901
2902 hds = append(c.xGoogHeaders, hds...)
2903 hds = append(hds, "Content-Type", "application/json")
2904 headers := gax.BuildHeaders(ctx, hds...)
2905 opts = append((*c.CallOptions).CreateGlossaryEntry[0:len((*c.CallOptions).CreateGlossaryEntry):len((*c.CallOptions).CreateGlossaryEntry)], opts...)
2906 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2907 resp := &translatepb.GlossaryEntry{}
2908 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2909 if settings.Path != "" {
2910 baseUrl.Path = settings.Path
2911 }
2912 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2913 if err != nil {
2914 return err
2915 }
2916 httpReq = httpReq.WithContext(ctx)
2917 httpReq.Header = headers
2918
2919 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateGlossaryEntry")
2920 if err != nil {
2921 return err
2922 }
2923
2924 if err := unm.Unmarshal(buf, resp); err != nil {
2925 return err
2926 }
2927
2928 return nil
2929 }, opts...)
2930 if e != nil {
2931 return nil, e
2932 }
2933 return resp, nil
2934 }
2935
2936 // UpdateGlossaryEntry updates a glossary entry.
2937 func (c *translationRESTClient) UpdateGlossaryEntry(ctx context.Context, req *translatepb.UpdateGlossaryEntryRequest, opts ...gax.CallOption) (*translatepb.GlossaryEntry, error) {
2938 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2939 body := req.GetGlossaryEntry()
2940 jsonReq, err := m.Marshal(body)
2941 if err != nil {
2942 return nil, err
2943 }
2944
2945 baseUrl, err := url.Parse(c.endpoint)
2946 if err != nil {
2947 return nil, err
2948 }
2949 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetGlossaryEntry().GetName())
2950
2951 params := url.Values{}
2952 params.Add("$alt", "json;enum-encoding=int")
2953
2954 baseUrl.RawQuery = params.Encode()
2955
2956 // Build HTTP headers from client and context metadata.
2957 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "glossary_entry.name", url.QueryEscape(req.GetGlossaryEntry().GetName()))}
2958
2959 hds = append(c.xGoogHeaders, hds...)
2960 hds = append(hds, "Content-Type", "application/json")
2961 headers := gax.BuildHeaders(ctx, hds...)
2962 opts = append((*c.CallOptions).UpdateGlossaryEntry[0:len((*c.CallOptions).UpdateGlossaryEntry):len((*c.CallOptions).UpdateGlossaryEntry)], opts...)
2963 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2964 resp := &translatepb.GlossaryEntry{}
2965 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2966 if settings.Path != "" {
2967 baseUrl.Path = settings.Path
2968 }
2969 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2970 if err != nil {
2971 return err
2972 }
2973 httpReq = httpReq.WithContext(ctx)
2974 httpReq.Header = headers
2975
2976 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateGlossaryEntry")
2977 if err != nil {
2978 return err
2979 }
2980
2981 if err := unm.Unmarshal(buf, resp); err != nil {
2982 return err
2983 }
2984
2985 return nil
2986 }, opts...)
2987 if e != nil {
2988 return nil, e
2989 }
2990 return resp, nil
2991 }
2992
2993 // DeleteGlossaryEntry deletes a single entry from the glossary
2994 func (c *translationRESTClient) DeleteGlossaryEntry(ctx context.Context, req *translatepb.DeleteGlossaryEntryRequest, opts ...gax.CallOption) error {
2995 baseUrl, err := url.Parse(c.endpoint)
2996 if err != nil {
2997 return err
2998 }
2999 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3000
3001 params := url.Values{}
3002 params.Add("$alt", "json;enum-encoding=int")
3003
3004 baseUrl.RawQuery = params.Encode()
3005
3006 // Build HTTP headers from client and context metadata.
3007 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3008
3009 hds = append(c.xGoogHeaders, hds...)
3010 hds = append(hds, "Content-Type", "application/json")
3011 headers := gax.BuildHeaders(ctx, hds...)
3012 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3013 if settings.Path != "" {
3014 baseUrl.Path = settings.Path
3015 }
3016 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3017 if err != nil {
3018 return err
3019 }
3020 httpReq = httpReq.WithContext(ctx)
3021 httpReq.Header = headers
3022
3023 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteGlossaryEntry")
3024 return err
3025 }, opts...)
3026 }
3027
3028 // CreateDataset creates a Dataset.
3029 func (c *translationRESTClient) CreateDataset(ctx context.Context, req *translatepb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) {
3030 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3031 body := req.GetDataset()
3032 jsonReq, err := m.Marshal(body)
3033 if err != nil {
3034 return nil, err
3035 }
3036
3037 baseUrl, err := url.Parse(c.endpoint)
3038 if err != nil {
3039 return nil, err
3040 }
3041 baseUrl.Path += fmt.Sprintf("/v3/%v/datasets", req.GetParent())
3042
3043 params := url.Values{}
3044 params.Add("$alt", "json;enum-encoding=int")
3045
3046 baseUrl.RawQuery = params.Encode()
3047
3048 // Build HTTP headers from client and context metadata.
3049 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3050
3051 hds = append(c.xGoogHeaders, hds...)
3052 hds = append(hds, "Content-Type", "application/json")
3053 headers := gax.BuildHeaders(ctx, hds...)
3054 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3055 resp := &longrunningpb.Operation{}
3056 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3057 if settings.Path != "" {
3058 baseUrl.Path = settings.Path
3059 }
3060 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3061 if err != nil {
3062 return err
3063 }
3064 httpReq = httpReq.WithContext(ctx)
3065 httpReq.Header = headers
3066
3067 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDataset")
3068 if err != nil {
3069 return err
3070 }
3071 if err := unm.Unmarshal(buf, resp); err != nil {
3072 return err
3073 }
3074
3075 return nil
3076 }, opts...)
3077 if e != nil {
3078 return nil, e
3079 }
3080
3081 override := fmt.Sprintf("/v3/%s", resp.GetName())
3082 return &CreateDatasetOperation{
3083 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3084 pollPath: override,
3085 }, nil
3086 }
3087
3088 // GetDataset gets a Dataset.
3089 func (c *translationRESTClient) GetDataset(ctx context.Context, req *translatepb.GetDatasetRequest, opts ...gax.CallOption) (*translatepb.Dataset, error) {
3090 baseUrl, err := url.Parse(c.endpoint)
3091 if err != nil {
3092 return nil, err
3093 }
3094 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3095
3096 params := url.Values{}
3097 params.Add("$alt", "json;enum-encoding=int")
3098
3099 baseUrl.RawQuery = params.Encode()
3100
3101 // Build HTTP headers from client and context metadata.
3102 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3103
3104 hds = append(c.xGoogHeaders, hds...)
3105 hds = append(hds, "Content-Type", "application/json")
3106 headers := gax.BuildHeaders(ctx, hds...)
3107 opts = append((*c.CallOptions).GetDataset[0:len((*c.CallOptions).GetDataset):len((*c.CallOptions).GetDataset)], opts...)
3108 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3109 resp := &translatepb.Dataset{}
3110 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3111 if settings.Path != "" {
3112 baseUrl.Path = settings.Path
3113 }
3114 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3115 if err != nil {
3116 return err
3117 }
3118 httpReq = httpReq.WithContext(ctx)
3119 httpReq.Header = headers
3120
3121 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDataset")
3122 if err != nil {
3123 return err
3124 }
3125
3126 if err := unm.Unmarshal(buf, resp); err != nil {
3127 return err
3128 }
3129
3130 return nil
3131 }, opts...)
3132 if e != nil {
3133 return nil, e
3134 }
3135 return resp, nil
3136 }
3137
3138 // ListDatasets lists datasets.
3139 func (c *translationRESTClient) ListDatasets(ctx context.Context, req *translatepb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator {
3140 it := &DatasetIterator{}
3141 req = proto.Clone(req).(*translatepb.ListDatasetsRequest)
3142 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3143 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Dataset, string, error) {
3144 resp := &translatepb.ListDatasetsResponse{}
3145 if pageToken != "" {
3146 req.PageToken = pageToken
3147 }
3148 if pageSize > math.MaxInt32 {
3149 req.PageSize = math.MaxInt32
3150 } else if pageSize != 0 {
3151 req.PageSize = int32(pageSize)
3152 }
3153 baseUrl, err := url.Parse(c.endpoint)
3154 if err != nil {
3155 return nil, "", err
3156 }
3157 baseUrl.Path += fmt.Sprintf("/v3/%v/datasets", req.GetParent())
3158
3159 params := url.Values{}
3160 params.Add("$alt", "json;enum-encoding=int")
3161 if req.GetPageSize() != 0 {
3162 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3163 }
3164 if req.GetPageToken() != "" {
3165 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3166 }
3167
3168 baseUrl.RawQuery = params.Encode()
3169
3170 // Build HTTP headers from client and context metadata.
3171 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
3172 headers := gax.BuildHeaders(ctx, hds...)
3173 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3174 if settings.Path != "" {
3175 baseUrl.Path = settings.Path
3176 }
3177 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3178 if err != nil {
3179 return err
3180 }
3181 httpReq.Header = headers
3182
3183 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDatasets")
3184 if err != nil {
3185 return err
3186 }
3187 if err := unm.Unmarshal(buf, resp); err != nil {
3188 return err
3189 }
3190
3191 return nil
3192 }, opts...)
3193 if e != nil {
3194 return nil, "", e
3195 }
3196 it.Response = resp
3197 return resp.GetDatasets(), resp.GetNextPageToken(), nil
3198 }
3199
3200 fetch := func(pageSize int, pageToken string) (string, error) {
3201 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
3202 if err != nil {
3203 return "", err
3204 }
3205 it.items = append(it.items, items...)
3206 return nextPageToken, nil
3207 }
3208
3209 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
3210 it.pageInfo.MaxSize = int(req.GetPageSize())
3211 it.pageInfo.Token = req.GetPageToken()
3212
3213 return it
3214 }
3215
3216 // DeleteDataset deletes a dataset and all of its contents.
3217 func (c *translationRESTClient) DeleteDataset(ctx context.Context, req *translatepb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) {
3218 baseUrl, err := url.Parse(c.endpoint)
3219 if err != nil {
3220 return nil, err
3221 }
3222 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3223
3224 params := url.Values{}
3225 params.Add("$alt", "json;enum-encoding=int")
3226
3227 baseUrl.RawQuery = params.Encode()
3228
3229 // Build HTTP headers from client and context metadata.
3230 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3231
3232 hds = append(c.xGoogHeaders, hds...)
3233 hds = append(hds, "Content-Type", "application/json")
3234 headers := gax.BuildHeaders(ctx, hds...)
3235 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3236 resp := &longrunningpb.Operation{}
3237 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3238 if settings.Path != "" {
3239 baseUrl.Path = settings.Path
3240 }
3241 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3242 if err != nil {
3243 return err
3244 }
3245 httpReq = httpReq.WithContext(ctx)
3246 httpReq.Header = headers
3247
3248 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDataset")
3249 if err != nil {
3250 return err
3251 }
3252 if err := unm.Unmarshal(buf, resp); err != nil {
3253 return err
3254 }
3255
3256 return nil
3257 }, opts...)
3258 if e != nil {
3259 return nil, e
3260 }
3261
3262 override := fmt.Sprintf("/v3/%s", resp.GetName())
3263 return &DeleteDatasetOperation{
3264 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3265 pollPath: override,
3266 }, nil
3267 }
3268
3269 // CreateAdaptiveMtDataset creates an Adaptive MT dataset.
3270 func (c *translationRESTClient) CreateAdaptiveMtDataset(ctx context.Context, req *translatepb.CreateAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
3271 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3272 body := req.GetAdaptiveMtDataset()
3273 jsonReq, err := m.Marshal(body)
3274 if err != nil {
3275 return nil, err
3276 }
3277
3278 baseUrl, err := url.Parse(c.endpoint)
3279 if err != nil {
3280 return nil, err
3281 }
3282 baseUrl.Path += fmt.Sprintf("/v3/%v/adaptiveMtDatasets", req.GetParent())
3283
3284 params := url.Values{}
3285 params.Add("$alt", "json;enum-encoding=int")
3286
3287 baseUrl.RawQuery = params.Encode()
3288
3289 // Build HTTP headers from client and context metadata.
3290 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3291
3292 hds = append(c.xGoogHeaders, hds...)
3293 hds = append(hds, "Content-Type", "application/json")
3294 headers := gax.BuildHeaders(ctx, hds...)
3295 opts = append((*c.CallOptions).CreateAdaptiveMtDataset[0:len((*c.CallOptions).CreateAdaptiveMtDataset):len((*c.CallOptions).CreateAdaptiveMtDataset)], opts...)
3296 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3297 resp := &translatepb.AdaptiveMtDataset{}
3298 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3299 if settings.Path != "" {
3300 baseUrl.Path = settings.Path
3301 }
3302 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3303 if err != nil {
3304 return err
3305 }
3306 httpReq = httpReq.WithContext(ctx)
3307 httpReq.Header = headers
3308
3309 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAdaptiveMtDataset")
3310 if err != nil {
3311 return err
3312 }
3313
3314 if err := unm.Unmarshal(buf, resp); err != nil {
3315 return err
3316 }
3317
3318 return nil
3319 }, opts...)
3320 if e != nil {
3321 return nil, e
3322 }
3323 return resp, nil
3324 }
3325
3326 // DeleteAdaptiveMtDataset deletes an Adaptive MT dataset, including all its entries and associated
3327 // metadata.
3328 func (c *translationRESTClient) DeleteAdaptiveMtDataset(ctx context.Context, req *translatepb.DeleteAdaptiveMtDatasetRequest, opts ...gax.CallOption) error {
3329 baseUrl, err := url.Parse(c.endpoint)
3330 if err != nil {
3331 return err
3332 }
3333 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3334
3335 params := url.Values{}
3336 params.Add("$alt", "json;enum-encoding=int")
3337
3338 baseUrl.RawQuery = params.Encode()
3339
3340 // Build HTTP headers from client and context metadata.
3341 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3342
3343 hds = append(c.xGoogHeaders, hds...)
3344 hds = append(hds, "Content-Type", "application/json")
3345 headers := gax.BuildHeaders(ctx, hds...)
3346 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3347 if settings.Path != "" {
3348 baseUrl.Path = settings.Path
3349 }
3350 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3351 if err != nil {
3352 return err
3353 }
3354 httpReq = httpReq.WithContext(ctx)
3355 httpReq.Header = headers
3356
3357 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAdaptiveMtDataset")
3358 return err
3359 }, opts...)
3360 }
3361
3362 // GetAdaptiveMtDataset gets the Adaptive MT dataset.
3363 func (c *translationRESTClient) GetAdaptiveMtDataset(ctx context.Context, req *translatepb.GetAdaptiveMtDatasetRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtDataset, error) {
3364 baseUrl, err := url.Parse(c.endpoint)
3365 if err != nil {
3366 return nil, err
3367 }
3368 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3369
3370 params := url.Values{}
3371 params.Add("$alt", "json;enum-encoding=int")
3372
3373 baseUrl.RawQuery = params.Encode()
3374
3375 // Build HTTP headers from client and context metadata.
3376 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3377
3378 hds = append(c.xGoogHeaders, hds...)
3379 hds = append(hds, "Content-Type", "application/json")
3380 headers := gax.BuildHeaders(ctx, hds...)
3381 opts = append((*c.CallOptions).GetAdaptiveMtDataset[0:len((*c.CallOptions).GetAdaptiveMtDataset):len((*c.CallOptions).GetAdaptiveMtDataset)], opts...)
3382 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3383 resp := &translatepb.AdaptiveMtDataset{}
3384 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3385 if settings.Path != "" {
3386 baseUrl.Path = settings.Path
3387 }
3388 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3389 if err != nil {
3390 return err
3391 }
3392 httpReq = httpReq.WithContext(ctx)
3393 httpReq.Header = headers
3394
3395 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAdaptiveMtDataset")
3396 if err != nil {
3397 return err
3398 }
3399
3400 if err := unm.Unmarshal(buf, resp); err != nil {
3401 return err
3402 }
3403
3404 return nil
3405 }, opts...)
3406 if e != nil {
3407 return nil, e
3408 }
3409 return resp, nil
3410 }
3411
3412 // ListAdaptiveMtDatasets lists all Adaptive MT datasets for which the caller has read permission.
3413 func (c *translationRESTClient) ListAdaptiveMtDatasets(ctx context.Context, req *translatepb.ListAdaptiveMtDatasetsRequest, opts ...gax.CallOption) *AdaptiveMtDatasetIterator {
3414 it := &AdaptiveMtDatasetIterator{}
3415 req = proto.Clone(req).(*translatepb.ListAdaptiveMtDatasetsRequest)
3416 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3417 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtDataset, string, error) {
3418 resp := &translatepb.ListAdaptiveMtDatasetsResponse{}
3419 if pageToken != "" {
3420 req.PageToken = pageToken
3421 }
3422 if pageSize > math.MaxInt32 {
3423 req.PageSize = math.MaxInt32
3424 } else if pageSize != 0 {
3425 req.PageSize = int32(pageSize)
3426 }
3427 baseUrl, err := url.Parse(c.endpoint)
3428 if err != nil {
3429 return nil, "", err
3430 }
3431 baseUrl.Path += fmt.Sprintf("/v3/%v/adaptiveMtDatasets", req.GetParent())
3432
3433 params := url.Values{}
3434 params.Add("$alt", "json;enum-encoding=int")
3435 if req.GetFilter() != "" {
3436 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
3437 }
3438 if req.GetPageSize() != 0 {
3439 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3440 }
3441 if req.GetPageToken() != "" {
3442 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3443 }
3444
3445 baseUrl.RawQuery = params.Encode()
3446
3447 // Build HTTP headers from client and context metadata.
3448 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
3449 headers := gax.BuildHeaders(ctx, hds...)
3450 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3451 if settings.Path != "" {
3452 baseUrl.Path = settings.Path
3453 }
3454 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3455 if err != nil {
3456 return err
3457 }
3458 httpReq.Header = headers
3459
3460 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAdaptiveMtDatasets")
3461 if err != nil {
3462 return err
3463 }
3464 if err := unm.Unmarshal(buf, resp); err != nil {
3465 return err
3466 }
3467
3468 return nil
3469 }, opts...)
3470 if e != nil {
3471 return nil, "", e
3472 }
3473 it.Response = resp
3474 return resp.GetAdaptiveMtDatasets(), resp.GetNextPageToken(), nil
3475 }
3476
3477 fetch := func(pageSize int, pageToken string) (string, error) {
3478 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
3479 if err != nil {
3480 return "", err
3481 }
3482 it.items = append(it.items, items...)
3483 return nextPageToken, nil
3484 }
3485
3486 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
3487 it.pageInfo.MaxSize = int(req.GetPageSize())
3488 it.pageInfo.Token = req.GetPageToken()
3489
3490 return it
3491 }
3492
3493 // AdaptiveMtTranslate translate text using Adaptive MT.
3494 func (c *translationRESTClient) AdaptiveMtTranslate(ctx context.Context, req *translatepb.AdaptiveMtTranslateRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtTranslateResponse, error) {
3495 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3496 jsonReq, err := m.Marshal(req)
3497 if err != nil {
3498 return nil, err
3499 }
3500
3501 baseUrl, err := url.Parse(c.endpoint)
3502 if err != nil {
3503 return nil, err
3504 }
3505 baseUrl.Path += fmt.Sprintf("/v3/%v:adaptiveMtTranslate", req.GetParent())
3506
3507 params := url.Values{}
3508 params.Add("$alt", "json;enum-encoding=int")
3509
3510 baseUrl.RawQuery = params.Encode()
3511
3512 // Build HTTP headers from client and context metadata.
3513 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3514
3515 hds = append(c.xGoogHeaders, hds...)
3516 hds = append(hds, "Content-Type", "application/json")
3517 headers := gax.BuildHeaders(ctx, hds...)
3518 opts = append((*c.CallOptions).AdaptiveMtTranslate[0:len((*c.CallOptions).AdaptiveMtTranslate):len((*c.CallOptions).AdaptiveMtTranslate)], opts...)
3519 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3520 resp := &translatepb.AdaptiveMtTranslateResponse{}
3521 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3522 if settings.Path != "" {
3523 baseUrl.Path = settings.Path
3524 }
3525 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3526 if err != nil {
3527 return err
3528 }
3529 httpReq = httpReq.WithContext(ctx)
3530 httpReq.Header = headers
3531
3532 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AdaptiveMtTranslate")
3533 if err != nil {
3534 return err
3535 }
3536
3537 if err := unm.Unmarshal(buf, resp); err != nil {
3538 return err
3539 }
3540
3541 return nil
3542 }, opts...)
3543 if e != nil {
3544 return nil, e
3545 }
3546 return resp, nil
3547 }
3548
3549 // GetAdaptiveMtFile gets and AdaptiveMtFile
3550 func (c *translationRESTClient) GetAdaptiveMtFile(ctx context.Context, req *translatepb.GetAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.AdaptiveMtFile, error) {
3551 baseUrl, err := url.Parse(c.endpoint)
3552 if err != nil {
3553 return nil, err
3554 }
3555 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3556
3557 params := url.Values{}
3558 params.Add("$alt", "json;enum-encoding=int")
3559
3560 baseUrl.RawQuery = params.Encode()
3561
3562 // Build HTTP headers from client and context metadata.
3563 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3564
3565 hds = append(c.xGoogHeaders, hds...)
3566 hds = append(hds, "Content-Type", "application/json")
3567 headers := gax.BuildHeaders(ctx, hds...)
3568 opts = append((*c.CallOptions).GetAdaptiveMtFile[0:len((*c.CallOptions).GetAdaptiveMtFile):len((*c.CallOptions).GetAdaptiveMtFile)], opts...)
3569 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3570 resp := &translatepb.AdaptiveMtFile{}
3571 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3572 if settings.Path != "" {
3573 baseUrl.Path = settings.Path
3574 }
3575 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3576 if err != nil {
3577 return err
3578 }
3579 httpReq = httpReq.WithContext(ctx)
3580 httpReq.Header = headers
3581
3582 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAdaptiveMtFile")
3583 if err != nil {
3584 return err
3585 }
3586
3587 if err := unm.Unmarshal(buf, resp); err != nil {
3588 return err
3589 }
3590
3591 return nil
3592 }, opts...)
3593 if e != nil {
3594 return nil, e
3595 }
3596 return resp, nil
3597 }
3598
3599 // DeleteAdaptiveMtFile deletes an AdaptiveMtFile along with its sentences.
3600 func (c *translationRESTClient) DeleteAdaptiveMtFile(ctx context.Context, req *translatepb.DeleteAdaptiveMtFileRequest, opts ...gax.CallOption) error {
3601 baseUrl, err := url.Parse(c.endpoint)
3602 if err != nil {
3603 return err
3604 }
3605 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
3606
3607 params := url.Values{}
3608 params.Add("$alt", "json;enum-encoding=int")
3609
3610 baseUrl.RawQuery = params.Encode()
3611
3612 // Build HTTP headers from client and context metadata.
3613 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3614
3615 hds = append(c.xGoogHeaders, hds...)
3616 hds = append(hds, "Content-Type", "application/json")
3617 headers := gax.BuildHeaders(ctx, hds...)
3618 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3619 if settings.Path != "" {
3620 baseUrl.Path = settings.Path
3621 }
3622 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3623 if err != nil {
3624 return err
3625 }
3626 httpReq = httpReq.WithContext(ctx)
3627 httpReq.Header = headers
3628
3629 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAdaptiveMtFile")
3630 return err
3631 }, opts...)
3632 }
3633
3634 // ImportAdaptiveMtFile imports an AdaptiveMtFile and adds all of its sentences into the
3635 // AdaptiveMtDataset.
3636 func (c *translationRESTClient) ImportAdaptiveMtFile(ctx context.Context, req *translatepb.ImportAdaptiveMtFileRequest, opts ...gax.CallOption) (*translatepb.ImportAdaptiveMtFileResponse, error) {
3637 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3638 jsonReq, err := m.Marshal(req)
3639 if err != nil {
3640 return nil, err
3641 }
3642
3643 baseUrl, err := url.Parse(c.endpoint)
3644 if err != nil {
3645 return nil, err
3646 }
3647 baseUrl.Path += fmt.Sprintf("/v3/%v:importAdaptiveMtFile", req.GetParent())
3648
3649 params := url.Values{}
3650 params.Add("$alt", "json;enum-encoding=int")
3651
3652 baseUrl.RawQuery = params.Encode()
3653
3654 // Build HTTP headers from client and context metadata.
3655 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3656
3657 hds = append(c.xGoogHeaders, hds...)
3658 hds = append(hds, "Content-Type", "application/json")
3659 headers := gax.BuildHeaders(ctx, hds...)
3660 opts = append((*c.CallOptions).ImportAdaptiveMtFile[0:len((*c.CallOptions).ImportAdaptiveMtFile):len((*c.CallOptions).ImportAdaptiveMtFile)], opts...)
3661 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3662 resp := &translatepb.ImportAdaptiveMtFileResponse{}
3663 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3664 if settings.Path != "" {
3665 baseUrl.Path = settings.Path
3666 }
3667 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3668 if err != nil {
3669 return err
3670 }
3671 httpReq = httpReq.WithContext(ctx)
3672 httpReq.Header = headers
3673
3674 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportAdaptiveMtFile")
3675 if err != nil {
3676 return err
3677 }
3678
3679 if err := unm.Unmarshal(buf, resp); err != nil {
3680 return err
3681 }
3682
3683 return nil
3684 }, opts...)
3685 if e != nil {
3686 return nil, e
3687 }
3688 return resp, nil
3689 }
3690
3691 // ListAdaptiveMtFiles lists all AdaptiveMtFiles associated to an AdaptiveMtDataset.
3692 func (c *translationRESTClient) ListAdaptiveMtFiles(ctx context.Context, req *translatepb.ListAdaptiveMtFilesRequest, opts ...gax.CallOption) *AdaptiveMtFileIterator {
3693 it := &AdaptiveMtFileIterator{}
3694 req = proto.Clone(req).(*translatepb.ListAdaptiveMtFilesRequest)
3695 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3696 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtFile, string, error) {
3697 resp := &translatepb.ListAdaptiveMtFilesResponse{}
3698 if pageToken != "" {
3699 req.PageToken = pageToken
3700 }
3701 if pageSize > math.MaxInt32 {
3702 req.PageSize = math.MaxInt32
3703 } else if pageSize != 0 {
3704 req.PageSize = int32(pageSize)
3705 }
3706 baseUrl, err := url.Parse(c.endpoint)
3707 if err != nil {
3708 return nil, "", err
3709 }
3710 baseUrl.Path += fmt.Sprintf("/v3/%v/adaptiveMtFiles", req.GetParent())
3711
3712 params := url.Values{}
3713 params.Add("$alt", "json;enum-encoding=int")
3714 if req.GetPageSize() != 0 {
3715 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3716 }
3717 if req.GetPageToken() != "" {
3718 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3719 }
3720
3721 baseUrl.RawQuery = params.Encode()
3722
3723 // Build HTTP headers from client and context metadata.
3724 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
3725 headers := gax.BuildHeaders(ctx, hds...)
3726 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3727 if settings.Path != "" {
3728 baseUrl.Path = settings.Path
3729 }
3730 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3731 if err != nil {
3732 return err
3733 }
3734 httpReq.Header = headers
3735
3736 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAdaptiveMtFiles")
3737 if err != nil {
3738 return err
3739 }
3740 if err := unm.Unmarshal(buf, resp); err != nil {
3741 return err
3742 }
3743
3744 return nil
3745 }, opts...)
3746 if e != nil {
3747 return nil, "", e
3748 }
3749 it.Response = resp
3750 return resp.GetAdaptiveMtFiles(), resp.GetNextPageToken(), nil
3751 }
3752
3753 fetch := func(pageSize int, pageToken string) (string, error) {
3754 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
3755 if err != nil {
3756 return "", err
3757 }
3758 it.items = append(it.items, items...)
3759 return nextPageToken, nil
3760 }
3761
3762 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
3763 it.pageInfo.MaxSize = int(req.GetPageSize())
3764 it.pageInfo.Token = req.GetPageToken()
3765
3766 return it
3767 }
3768
3769 // ListAdaptiveMtSentences lists all AdaptiveMtSentences under a given file/dataset.
3770 func (c *translationRESTClient) ListAdaptiveMtSentences(ctx context.Context, req *translatepb.ListAdaptiveMtSentencesRequest, opts ...gax.CallOption) *AdaptiveMtSentenceIterator {
3771 it := &AdaptiveMtSentenceIterator{}
3772 req = proto.Clone(req).(*translatepb.ListAdaptiveMtSentencesRequest)
3773 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3774 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.AdaptiveMtSentence, string, error) {
3775 resp := &translatepb.ListAdaptiveMtSentencesResponse{}
3776 if pageToken != "" {
3777 req.PageToken = pageToken
3778 }
3779 if pageSize > math.MaxInt32 {
3780 req.PageSize = math.MaxInt32
3781 } else if pageSize != 0 {
3782 req.PageSize = int32(pageSize)
3783 }
3784 baseUrl, err := url.Parse(c.endpoint)
3785 if err != nil {
3786 return nil, "", err
3787 }
3788 baseUrl.Path += fmt.Sprintf("/v3/%v/adaptiveMtSentences", req.GetParent())
3789
3790 params := url.Values{}
3791 params.Add("$alt", "json;enum-encoding=int")
3792 if req.GetPageSize() != 0 {
3793 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3794 }
3795 if req.GetPageToken() != "" {
3796 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3797 }
3798
3799 baseUrl.RawQuery = params.Encode()
3800
3801 // Build HTTP headers from client and context metadata.
3802 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
3803 headers := gax.BuildHeaders(ctx, hds...)
3804 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3805 if settings.Path != "" {
3806 baseUrl.Path = settings.Path
3807 }
3808 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3809 if err != nil {
3810 return err
3811 }
3812 httpReq.Header = headers
3813
3814 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAdaptiveMtSentences")
3815 if err != nil {
3816 return err
3817 }
3818 if err := unm.Unmarshal(buf, resp); err != nil {
3819 return err
3820 }
3821
3822 return nil
3823 }, opts...)
3824 if e != nil {
3825 return nil, "", e
3826 }
3827 it.Response = resp
3828 return resp.GetAdaptiveMtSentences(), resp.GetNextPageToken(), nil
3829 }
3830
3831 fetch := func(pageSize int, pageToken string) (string, error) {
3832 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
3833 if err != nil {
3834 return "", err
3835 }
3836 it.items = append(it.items, items...)
3837 return nextPageToken, nil
3838 }
3839
3840 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
3841 it.pageInfo.MaxSize = int(req.GetPageSize())
3842 it.pageInfo.Token = req.GetPageToken()
3843
3844 return it
3845 }
3846
3847 // ImportData import sentence pairs into translation Dataset.
3848 func (c *translationRESTClient) ImportData(ctx context.Context, req *translatepb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) {
3849 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3850 jsonReq, err := m.Marshal(req)
3851 if err != nil {
3852 return nil, err
3853 }
3854
3855 baseUrl, err := url.Parse(c.endpoint)
3856 if err != nil {
3857 return nil, err
3858 }
3859 baseUrl.Path += fmt.Sprintf("/v3/%v:importData", req.GetDataset())
3860
3861 params := url.Values{}
3862 params.Add("$alt", "json;enum-encoding=int")
3863
3864 baseUrl.RawQuery = params.Encode()
3865
3866 // Build HTTP headers from client and context metadata.
3867 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset", url.QueryEscape(req.GetDataset()))}
3868
3869 hds = append(c.xGoogHeaders, hds...)
3870 hds = append(hds, "Content-Type", "application/json")
3871 headers := gax.BuildHeaders(ctx, hds...)
3872 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3873 resp := &longrunningpb.Operation{}
3874 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3875 if settings.Path != "" {
3876 baseUrl.Path = settings.Path
3877 }
3878 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3879 if err != nil {
3880 return err
3881 }
3882 httpReq = httpReq.WithContext(ctx)
3883 httpReq.Header = headers
3884
3885 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportData")
3886 if err != nil {
3887 return err
3888 }
3889 if err := unm.Unmarshal(buf, resp); err != nil {
3890 return err
3891 }
3892
3893 return nil
3894 }, opts...)
3895 if e != nil {
3896 return nil, e
3897 }
3898
3899 override := fmt.Sprintf("/v3/%s", resp.GetName())
3900 return &ImportDataOperation{
3901 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3902 pollPath: override,
3903 }, nil
3904 }
3905
3906 // ExportData exports dataset’s data to the provided output location.
3907 func (c *translationRESTClient) ExportData(ctx context.Context, req *translatepb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) {
3908 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3909 jsonReq, err := m.Marshal(req)
3910 if err != nil {
3911 return nil, err
3912 }
3913
3914 baseUrl, err := url.Parse(c.endpoint)
3915 if err != nil {
3916 return nil, err
3917 }
3918 baseUrl.Path += fmt.Sprintf("/v3/%v:exportData", req.GetDataset())
3919
3920 params := url.Values{}
3921 params.Add("$alt", "json;enum-encoding=int")
3922
3923 baseUrl.RawQuery = params.Encode()
3924
3925 // Build HTTP headers from client and context metadata.
3926 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset", url.QueryEscape(req.GetDataset()))}
3927
3928 hds = append(c.xGoogHeaders, hds...)
3929 hds = append(hds, "Content-Type", "application/json")
3930 headers := gax.BuildHeaders(ctx, hds...)
3931 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3932 resp := &longrunningpb.Operation{}
3933 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3934 if settings.Path != "" {
3935 baseUrl.Path = settings.Path
3936 }
3937 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3938 if err != nil {
3939 return err
3940 }
3941 httpReq = httpReq.WithContext(ctx)
3942 httpReq.Header = headers
3943
3944 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ExportData")
3945 if err != nil {
3946 return err
3947 }
3948 if err := unm.Unmarshal(buf, resp); err != nil {
3949 return err
3950 }
3951
3952 return nil
3953 }, opts...)
3954 if e != nil {
3955 return nil, e
3956 }
3957
3958 override := fmt.Sprintf("/v3/%s", resp.GetName())
3959 return &ExportDataOperation{
3960 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3961 pollPath: override,
3962 }, nil
3963 }
3964
3965 // ListExamples lists sentence pairs in the dataset.
3966 func (c *translationRESTClient) ListExamples(ctx context.Context, req *translatepb.ListExamplesRequest, opts ...gax.CallOption) *ExampleIterator {
3967 it := &ExampleIterator{}
3968 req = proto.Clone(req).(*translatepb.ListExamplesRequest)
3969 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3970 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Example, string, error) {
3971 resp := &translatepb.ListExamplesResponse{}
3972 if pageToken != "" {
3973 req.PageToken = pageToken
3974 }
3975 if pageSize > math.MaxInt32 {
3976 req.PageSize = math.MaxInt32
3977 } else if pageSize != 0 {
3978 req.PageSize = int32(pageSize)
3979 }
3980 baseUrl, err := url.Parse(c.endpoint)
3981 if err != nil {
3982 return nil, "", err
3983 }
3984 baseUrl.Path += fmt.Sprintf("/v3/%v/examples", req.GetParent())
3985
3986 params := url.Values{}
3987 params.Add("$alt", "json;enum-encoding=int")
3988 if req.GetFilter() != "" {
3989 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
3990 }
3991 if req.GetPageSize() != 0 {
3992 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3993 }
3994 if req.GetPageToken() != "" {
3995 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3996 }
3997
3998 baseUrl.RawQuery = params.Encode()
3999
4000 // Build HTTP headers from client and context metadata.
4001 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
4002 headers := gax.BuildHeaders(ctx, hds...)
4003 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4004 if settings.Path != "" {
4005 baseUrl.Path = settings.Path
4006 }
4007 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4008 if err != nil {
4009 return err
4010 }
4011 httpReq.Header = headers
4012
4013 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListExamples")
4014 if err != nil {
4015 return err
4016 }
4017 if err := unm.Unmarshal(buf, resp); err != nil {
4018 return err
4019 }
4020
4021 return nil
4022 }, opts...)
4023 if e != nil {
4024 return nil, "", e
4025 }
4026 it.Response = resp
4027 return resp.GetExamples(), resp.GetNextPageToken(), nil
4028 }
4029
4030 fetch := func(pageSize int, pageToken string) (string, error) {
4031 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
4032 if err != nil {
4033 return "", err
4034 }
4035 it.items = append(it.items, items...)
4036 return nextPageToken, nil
4037 }
4038
4039 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
4040 it.pageInfo.MaxSize = int(req.GetPageSize())
4041 it.pageInfo.Token = req.GetPageToken()
4042
4043 return it
4044 }
4045
4046 // CreateModel creates a Model.
4047 func (c *translationRESTClient) CreateModel(ctx context.Context, req *translatepb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) {
4048 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
4049 body := req.GetModel()
4050 jsonReq, err := m.Marshal(body)
4051 if err != nil {
4052 return nil, err
4053 }
4054
4055 baseUrl, err := url.Parse(c.endpoint)
4056 if err != nil {
4057 return nil, err
4058 }
4059 baseUrl.Path += fmt.Sprintf("/v3/%v/models", req.GetParent())
4060
4061 params := url.Values{}
4062 params.Add("$alt", "json;enum-encoding=int")
4063
4064 baseUrl.RawQuery = params.Encode()
4065
4066 // Build HTTP headers from client and context metadata.
4067 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
4068
4069 hds = append(c.xGoogHeaders, hds...)
4070 hds = append(hds, "Content-Type", "application/json")
4071 headers := gax.BuildHeaders(ctx, hds...)
4072 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4073 resp := &longrunningpb.Operation{}
4074 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4075 if settings.Path != "" {
4076 baseUrl.Path = settings.Path
4077 }
4078 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
4079 if err != nil {
4080 return err
4081 }
4082 httpReq = httpReq.WithContext(ctx)
4083 httpReq.Header = headers
4084
4085 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateModel")
4086 if err != nil {
4087 return err
4088 }
4089 if err := unm.Unmarshal(buf, resp); err != nil {
4090 return err
4091 }
4092
4093 return nil
4094 }, opts...)
4095 if e != nil {
4096 return nil, e
4097 }
4098
4099 override := fmt.Sprintf("/v3/%s", resp.GetName())
4100 return &CreateModelOperation{
4101 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
4102 pollPath: override,
4103 }, nil
4104 }
4105
4106 // ListModels lists models.
4107 func (c *translationRESTClient) ListModels(ctx context.Context, req *translatepb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator {
4108 it := &ModelIterator{}
4109 req = proto.Clone(req).(*translatepb.ListModelsRequest)
4110 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4111 it.InternalFetch = func(pageSize int, pageToken string) ([]*translatepb.Model, string, error) {
4112 resp := &translatepb.ListModelsResponse{}
4113 if pageToken != "" {
4114 req.PageToken = pageToken
4115 }
4116 if pageSize > math.MaxInt32 {
4117 req.PageSize = math.MaxInt32
4118 } else if pageSize != 0 {
4119 req.PageSize = int32(pageSize)
4120 }
4121 baseUrl, err := url.Parse(c.endpoint)
4122 if err != nil {
4123 return nil, "", err
4124 }
4125 baseUrl.Path += fmt.Sprintf("/v3/%v/models", req.GetParent())
4126
4127 params := url.Values{}
4128 params.Add("$alt", "json;enum-encoding=int")
4129 if req.GetFilter() != "" {
4130 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
4131 }
4132 if req.GetPageSize() != 0 {
4133 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
4134 }
4135 if req.GetPageToken() != "" {
4136 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
4137 }
4138
4139 baseUrl.RawQuery = params.Encode()
4140
4141 // Build HTTP headers from client and context metadata.
4142 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
4143 headers := gax.BuildHeaders(ctx, hds...)
4144 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4145 if settings.Path != "" {
4146 baseUrl.Path = settings.Path
4147 }
4148 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4149 if err != nil {
4150 return err
4151 }
4152 httpReq.Header = headers
4153
4154 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListModels")
4155 if err != nil {
4156 return err
4157 }
4158 if err := unm.Unmarshal(buf, resp); err != nil {
4159 return err
4160 }
4161
4162 return nil
4163 }, opts...)
4164 if e != nil {
4165 return nil, "", e
4166 }
4167 it.Response = resp
4168 return resp.GetModels(), resp.GetNextPageToken(), nil
4169 }
4170
4171 fetch := func(pageSize int, pageToken string) (string, error) {
4172 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
4173 if err != nil {
4174 return "", err
4175 }
4176 it.items = append(it.items, items...)
4177 return nextPageToken, nil
4178 }
4179
4180 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
4181 it.pageInfo.MaxSize = int(req.GetPageSize())
4182 it.pageInfo.Token = req.GetPageToken()
4183
4184 return it
4185 }
4186
4187 // GetModel gets a model.
4188 func (c *translationRESTClient) GetModel(ctx context.Context, req *translatepb.GetModelRequest, opts ...gax.CallOption) (*translatepb.Model, error) {
4189 baseUrl, err := url.Parse(c.endpoint)
4190 if err != nil {
4191 return nil, err
4192 }
4193 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
4194
4195 params := url.Values{}
4196 params.Add("$alt", "json;enum-encoding=int")
4197
4198 baseUrl.RawQuery = params.Encode()
4199
4200 // Build HTTP headers from client and context metadata.
4201 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4202
4203 hds = append(c.xGoogHeaders, hds...)
4204 hds = append(hds, "Content-Type", "application/json")
4205 headers := gax.BuildHeaders(ctx, hds...)
4206 opts = append((*c.CallOptions).GetModel[0:len((*c.CallOptions).GetModel):len((*c.CallOptions).GetModel)], opts...)
4207 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4208 resp := &translatepb.Model{}
4209 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4210 if settings.Path != "" {
4211 baseUrl.Path = settings.Path
4212 }
4213 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4214 if err != nil {
4215 return err
4216 }
4217 httpReq = httpReq.WithContext(ctx)
4218 httpReq.Header = headers
4219
4220 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetModel")
4221 if err != nil {
4222 return err
4223 }
4224
4225 if err := unm.Unmarshal(buf, resp); err != nil {
4226 return err
4227 }
4228
4229 return nil
4230 }, opts...)
4231 if e != nil {
4232 return nil, e
4233 }
4234 return resp, nil
4235 }
4236
4237 // DeleteModel deletes a model.
4238 func (c *translationRESTClient) DeleteModel(ctx context.Context, req *translatepb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) {
4239 baseUrl, err := url.Parse(c.endpoint)
4240 if err != nil {
4241 return nil, err
4242 }
4243 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
4244
4245 params := url.Values{}
4246 params.Add("$alt", "json;enum-encoding=int")
4247
4248 baseUrl.RawQuery = params.Encode()
4249
4250 // Build HTTP headers from client and context metadata.
4251 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4252
4253 hds = append(c.xGoogHeaders, hds...)
4254 hds = append(hds, "Content-Type", "application/json")
4255 headers := gax.BuildHeaders(ctx, hds...)
4256 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4257 resp := &longrunningpb.Operation{}
4258 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4259 if settings.Path != "" {
4260 baseUrl.Path = settings.Path
4261 }
4262 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
4263 if err != nil {
4264 return err
4265 }
4266 httpReq = httpReq.WithContext(ctx)
4267 httpReq.Header = headers
4268
4269 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteModel")
4270 if err != nil {
4271 return err
4272 }
4273 if err := unm.Unmarshal(buf, resp); err != nil {
4274 return err
4275 }
4276
4277 return nil
4278 }, opts...)
4279 if e != nil {
4280 return nil, e
4281 }
4282
4283 override := fmt.Sprintf("/v3/%s", resp.GetName())
4284 return &DeleteModelOperation{
4285 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
4286 pollPath: override,
4287 }, nil
4288 }
4289
4290 // GetLocation gets information about a location.
4291 func (c *translationRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
4292 baseUrl, err := url.Parse(c.endpoint)
4293 if err != nil {
4294 return nil, err
4295 }
4296 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
4297
4298 params := url.Values{}
4299 params.Add("$alt", "json;enum-encoding=int")
4300
4301 baseUrl.RawQuery = params.Encode()
4302
4303 // Build HTTP headers from client and context metadata.
4304 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4305
4306 hds = append(c.xGoogHeaders, hds...)
4307 hds = append(hds, "Content-Type", "application/json")
4308 headers := gax.BuildHeaders(ctx, hds...)
4309 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
4310 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4311 resp := &locationpb.Location{}
4312 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4313 if settings.Path != "" {
4314 baseUrl.Path = settings.Path
4315 }
4316 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4317 if err != nil {
4318 return err
4319 }
4320 httpReq = httpReq.WithContext(ctx)
4321 httpReq.Header = headers
4322
4323 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
4324 if err != nil {
4325 return err
4326 }
4327
4328 if err := unm.Unmarshal(buf, resp); err != nil {
4329 return err
4330 }
4331
4332 return nil
4333 }, opts...)
4334 if e != nil {
4335 return nil, e
4336 }
4337 return resp, nil
4338 }
4339
4340 // ListLocations lists information about the supported locations for this service.
4341 func (c *translationRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
4342 it := &LocationIterator{}
4343 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
4344 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4345 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
4346 resp := &locationpb.ListLocationsResponse{}
4347 if pageToken != "" {
4348 req.PageToken = pageToken
4349 }
4350 if pageSize > math.MaxInt32 {
4351 req.PageSize = math.MaxInt32
4352 } else if pageSize != 0 {
4353 req.PageSize = int32(pageSize)
4354 }
4355 baseUrl, err := url.Parse(c.endpoint)
4356 if err != nil {
4357 return nil, "", err
4358 }
4359 baseUrl.Path += fmt.Sprintf("/v3/%v/locations", req.GetName())
4360
4361 params := url.Values{}
4362 params.Add("$alt", "json;enum-encoding=int")
4363 if req.GetFilter() != "" {
4364 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
4365 }
4366 if req.GetPageSize() != 0 {
4367 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
4368 }
4369 if req.GetPageToken() != "" {
4370 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
4371 }
4372
4373 baseUrl.RawQuery = params.Encode()
4374
4375 // Build HTTP headers from client and context metadata.
4376 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
4377 headers := gax.BuildHeaders(ctx, hds...)
4378 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4379 if settings.Path != "" {
4380 baseUrl.Path = settings.Path
4381 }
4382 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4383 if err != nil {
4384 return err
4385 }
4386 httpReq.Header = headers
4387
4388 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
4389 if err != nil {
4390 return err
4391 }
4392 if err := unm.Unmarshal(buf, resp); err != nil {
4393 return err
4394 }
4395
4396 return nil
4397 }, opts...)
4398 if e != nil {
4399 return nil, "", e
4400 }
4401 it.Response = resp
4402 return resp.GetLocations(), resp.GetNextPageToken(), nil
4403 }
4404
4405 fetch := func(pageSize int, pageToken string) (string, error) {
4406 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
4407 if err != nil {
4408 return "", err
4409 }
4410 it.items = append(it.items, items...)
4411 return nextPageToken, nil
4412 }
4413
4414 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
4415 it.pageInfo.MaxSize = int(req.GetPageSize())
4416 it.pageInfo.Token = req.GetPageToken()
4417
4418 return it
4419 }
4420
4421 // CancelOperation is a utility method from google.longrunning.Operations.
4422 func (c *translationRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
4423 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
4424 jsonReq, err := m.Marshal(req)
4425 if err != nil {
4426 return err
4427 }
4428
4429 baseUrl, err := url.Parse(c.endpoint)
4430 if err != nil {
4431 return err
4432 }
4433 baseUrl.Path += fmt.Sprintf("/v3/%v:cancel", req.GetName())
4434
4435 params := url.Values{}
4436 params.Add("$alt", "json;enum-encoding=int")
4437
4438 baseUrl.RawQuery = params.Encode()
4439
4440 // Build HTTP headers from client and context metadata.
4441 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4442
4443 hds = append(c.xGoogHeaders, hds...)
4444 hds = append(hds, "Content-Type", "application/json")
4445 headers := gax.BuildHeaders(ctx, hds...)
4446 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4447 if settings.Path != "" {
4448 baseUrl.Path = settings.Path
4449 }
4450 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
4451 if err != nil {
4452 return err
4453 }
4454 httpReq = httpReq.WithContext(ctx)
4455 httpReq.Header = headers
4456
4457 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
4458 return err
4459 }, opts...)
4460 }
4461
4462 // DeleteOperation is a utility method from google.longrunning.Operations.
4463 func (c *translationRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
4464 baseUrl, err := url.Parse(c.endpoint)
4465 if err != nil {
4466 return err
4467 }
4468 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
4469
4470 params := url.Values{}
4471 params.Add("$alt", "json;enum-encoding=int")
4472
4473 baseUrl.RawQuery = params.Encode()
4474
4475 // Build HTTP headers from client and context metadata.
4476 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4477
4478 hds = append(c.xGoogHeaders, hds...)
4479 hds = append(hds, "Content-Type", "application/json")
4480 headers := gax.BuildHeaders(ctx, hds...)
4481 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4482 if settings.Path != "" {
4483 baseUrl.Path = settings.Path
4484 }
4485 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
4486 if err != nil {
4487 return err
4488 }
4489 httpReq = httpReq.WithContext(ctx)
4490 httpReq.Header = headers
4491
4492 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
4493 return err
4494 }, opts...)
4495 }
4496
4497 // GetOperation is a utility method from google.longrunning.Operations.
4498 func (c *translationRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
4499 baseUrl, err := url.Parse(c.endpoint)
4500 if err != nil {
4501 return nil, err
4502 }
4503 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
4504
4505 params := url.Values{}
4506 params.Add("$alt", "json;enum-encoding=int")
4507
4508 baseUrl.RawQuery = params.Encode()
4509
4510 // Build HTTP headers from client and context metadata.
4511 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4512
4513 hds = append(c.xGoogHeaders, hds...)
4514 hds = append(hds, "Content-Type", "application/json")
4515 headers := gax.BuildHeaders(ctx, hds...)
4516 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
4517 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4518 resp := &longrunningpb.Operation{}
4519 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4520 if settings.Path != "" {
4521 baseUrl.Path = settings.Path
4522 }
4523 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4524 if err != nil {
4525 return err
4526 }
4527 httpReq = httpReq.WithContext(ctx)
4528 httpReq.Header = headers
4529
4530 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
4531 if err != nil {
4532 return err
4533 }
4534
4535 if err := unm.Unmarshal(buf, resp); err != nil {
4536 return err
4537 }
4538
4539 return nil
4540 }, opts...)
4541 if e != nil {
4542 return nil, e
4543 }
4544 return resp, nil
4545 }
4546
4547 // ListOperations is a utility method from google.longrunning.Operations.
4548 func (c *translationRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
4549 it := &OperationIterator{}
4550 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
4551 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4552 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
4553 resp := &longrunningpb.ListOperationsResponse{}
4554 if pageToken != "" {
4555 req.PageToken = pageToken
4556 }
4557 if pageSize > math.MaxInt32 {
4558 req.PageSize = math.MaxInt32
4559 } else if pageSize != 0 {
4560 req.PageSize = int32(pageSize)
4561 }
4562 baseUrl, err := url.Parse(c.endpoint)
4563 if err != nil {
4564 return nil, "", err
4565 }
4566 baseUrl.Path += fmt.Sprintf("/v3/%v/operations", req.GetName())
4567
4568 params := url.Values{}
4569 params.Add("$alt", "json;enum-encoding=int")
4570 if req.GetFilter() != "" {
4571 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
4572 }
4573 if req.GetPageSize() != 0 {
4574 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
4575 }
4576 if req.GetPageToken() != "" {
4577 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
4578 }
4579
4580 baseUrl.RawQuery = params.Encode()
4581
4582 // Build HTTP headers from client and context metadata.
4583 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
4584 headers := gax.BuildHeaders(ctx, hds...)
4585 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4586 if settings.Path != "" {
4587 baseUrl.Path = settings.Path
4588 }
4589 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
4590 if err != nil {
4591 return err
4592 }
4593 httpReq.Header = headers
4594
4595 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
4596 if err != nil {
4597 return err
4598 }
4599 if err := unm.Unmarshal(buf, resp); err != nil {
4600 return err
4601 }
4602
4603 return nil
4604 }, opts...)
4605 if e != nil {
4606 return nil, "", e
4607 }
4608 it.Response = resp
4609 return resp.GetOperations(), resp.GetNextPageToken(), nil
4610 }
4611
4612 fetch := func(pageSize int, pageToken string) (string, error) {
4613 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
4614 if err != nil {
4615 return "", err
4616 }
4617 it.items = append(it.items, items...)
4618 return nextPageToken, nil
4619 }
4620
4621 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
4622 it.pageInfo.MaxSize = int(req.GetPageSize())
4623 it.pageInfo.Token = req.GetPageToken()
4624
4625 return it
4626 }
4627
4628 // WaitOperation is a utility method from google.longrunning.Operations.
4629 func (c *translationRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
4630 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
4631 jsonReq, err := m.Marshal(req)
4632 if err != nil {
4633 return nil, err
4634 }
4635
4636 baseUrl, err := url.Parse(c.endpoint)
4637 if err != nil {
4638 return nil, err
4639 }
4640 baseUrl.Path += fmt.Sprintf("/v3/%v:wait", req.GetName())
4641
4642 params := url.Values{}
4643 params.Add("$alt", "json;enum-encoding=int")
4644
4645 baseUrl.RawQuery = params.Encode()
4646
4647 // Build HTTP headers from client and context metadata.
4648 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
4649
4650 hds = append(c.xGoogHeaders, hds...)
4651 hds = append(hds, "Content-Type", "application/json")
4652 headers := gax.BuildHeaders(ctx, hds...)
4653 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
4654 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
4655 resp := &longrunningpb.Operation{}
4656 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
4657 if settings.Path != "" {
4658 baseUrl.Path = settings.Path
4659 }
4660 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
4661 if err != nil {
4662 return err
4663 }
4664 httpReq = httpReq.WithContext(ctx)
4665 httpReq.Header = headers
4666
4667 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "WaitOperation")
4668 if err != nil {
4669 return err
4670 }
4671
4672 if err := unm.Unmarshal(buf, resp); err != nil {
4673 return err
4674 }
4675
4676 return nil
4677 }, opts...)
4678 if e != nil {
4679 return nil, e
4680 }
4681 return resp, nil
4682 }
4683
4684 // BatchTranslateDocumentOperation returns a new BatchTranslateDocumentOperation from a given name.
4685 // The name must be that of a previously created BatchTranslateDocumentOperation, possibly from a different process.
4686 func (c *translationGRPCClient) BatchTranslateDocumentOperation(name string) *BatchTranslateDocumentOperation {
4687 return &BatchTranslateDocumentOperation{
4688 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4689 }
4690 }
4691
4692 // BatchTranslateDocumentOperation returns a new BatchTranslateDocumentOperation from a given name.
4693 // The name must be that of a previously created BatchTranslateDocumentOperation, possibly from a different process.
4694 func (c *translationRESTClient) BatchTranslateDocumentOperation(name string) *BatchTranslateDocumentOperation {
4695 override := fmt.Sprintf("/v3/%s", name)
4696 return &BatchTranslateDocumentOperation{
4697 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4698 pollPath: override,
4699 }
4700 }
4701
4702 // BatchTranslateTextOperation returns a new BatchTranslateTextOperation from a given name.
4703 // The name must be that of a previously created BatchTranslateTextOperation, possibly from a different process.
4704 func (c *translationGRPCClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation {
4705 return &BatchTranslateTextOperation{
4706 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4707 }
4708 }
4709
4710 // BatchTranslateTextOperation returns a new BatchTranslateTextOperation from a given name.
4711 // The name must be that of a previously created BatchTranslateTextOperation, possibly from a different process.
4712 func (c *translationRESTClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation {
4713 override := fmt.Sprintf("/v3/%s", name)
4714 return &BatchTranslateTextOperation{
4715 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4716 pollPath: override,
4717 }
4718 }
4719
4720 // CreateDatasetOperation returns a new CreateDatasetOperation from a given name.
4721 // The name must be that of a previously created CreateDatasetOperation, possibly from a different process.
4722 func (c *translationGRPCClient) CreateDatasetOperation(name string) *CreateDatasetOperation {
4723 return &CreateDatasetOperation{
4724 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4725 }
4726 }
4727
4728 // CreateDatasetOperation returns a new CreateDatasetOperation from a given name.
4729 // The name must be that of a previously created CreateDatasetOperation, possibly from a different process.
4730 func (c *translationRESTClient) CreateDatasetOperation(name string) *CreateDatasetOperation {
4731 override := fmt.Sprintf("/v3/%s", name)
4732 return &CreateDatasetOperation{
4733 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4734 pollPath: override,
4735 }
4736 }
4737
4738 // CreateGlossaryOperation returns a new CreateGlossaryOperation from a given name.
4739 // The name must be that of a previously created CreateGlossaryOperation, possibly from a different process.
4740 func (c *translationGRPCClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation {
4741 return &CreateGlossaryOperation{
4742 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4743 }
4744 }
4745
4746 // CreateGlossaryOperation returns a new CreateGlossaryOperation from a given name.
4747 // The name must be that of a previously created CreateGlossaryOperation, possibly from a different process.
4748 func (c *translationRESTClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation {
4749 override := fmt.Sprintf("/v3/%s", name)
4750 return &CreateGlossaryOperation{
4751 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4752 pollPath: override,
4753 }
4754 }
4755
4756 // CreateModelOperation returns a new CreateModelOperation from a given name.
4757 // The name must be that of a previously created CreateModelOperation, possibly from a different process.
4758 func (c *translationGRPCClient) CreateModelOperation(name string) *CreateModelOperation {
4759 return &CreateModelOperation{
4760 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4761 }
4762 }
4763
4764 // CreateModelOperation returns a new CreateModelOperation from a given name.
4765 // The name must be that of a previously created CreateModelOperation, possibly from a different process.
4766 func (c *translationRESTClient) CreateModelOperation(name string) *CreateModelOperation {
4767 override := fmt.Sprintf("/v3/%s", name)
4768 return &CreateModelOperation{
4769 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4770 pollPath: override,
4771 }
4772 }
4773
4774 // DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name.
4775 // The name must be that of a previously created DeleteDatasetOperation, possibly from a different process.
4776 func (c *translationGRPCClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation {
4777 return &DeleteDatasetOperation{
4778 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4779 }
4780 }
4781
4782 // DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name.
4783 // The name must be that of a previously created DeleteDatasetOperation, possibly from a different process.
4784 func (c *translationRESTClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation {
4785 override := fmt.Sprintf("/v3/%s", name)
4786 return &DeleteDatasetOperation{
4787 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4788 pollPath: override,
4789 }
4790 }
4791
4792 // DeleteGlossaryOperation returns a new DeleteGlossaryOperation from a given name.
4793 // The name must be that of a previously created DeleteGlossaryOperation, possibly from a different process.
4794 func (c *translationGRPCClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation {
4795 return &DeleteGlossaryOperation{
4796 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4797 }
4798 }
4799
4800 // DeleteGlossaryOperation returns a new DeleteGlossaryOperation from a given name.
4801 // The name must be that of a previously created DeleteGlossaryOperation, possibly from a different process.
4802 func (c *translationRESTClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation {
4803 override := fmt.Sprintf("/v3/%s", name)
4804 return &DeleteGlossaryOperation{
4805 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4806 pollPath: override,
4807 }
4808 }
4809
4810 // DeleteModelOperation returns a new DeleteModelOperation from a given name.
4811 // The name must be that of a previously created DeleteModelOperation, possibly from a different process.
4812 func (c *translationGRPCClient) DeleteModelOperation(name string) *DeleteModelOperation {
4813 return &DeleteModelOperation{
4814 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4815 }
4816 }
4817
4818 // DeleteModelOperation returns a new DeleteModelOperation from a given name.
4819 // The name must be that of a previously created DeleteModelOperation, possibly from a different process.
4820 func (c *translationRESTClient) DeleteModelOperation(name string) *DeleteModelOperation {
4821 override := fmt.Sprintf("/v3/%s", name)
4822 return &DeleteModelOperation{
4823 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4824 pollPath: override,
4825 }
4826 }
4827
4828 // ExportDataOperation returns a new ExportDataOperation from a given name.
4829 // The name must be that of a previously created ExportDataOperation, possibly from a different process.
4830 func (c *translationGRPCClient) ExportDataOperation(name string) *ExportDataOperation {
4831 return &ExportDataOperation{
4832 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4833 }
4834 }
4835
4836 // ExportDataOperation returns a new ExportDataOperation from a given name.
4837 // The name must be that of a previously created ExportDataOperation, possibly from a different process.
4838 func (c *translationRESTClient) ExportDataOperation(name string) *ExportDataOperation {
4839 override := fmt.Sprintf("/v3/%s", name)
4840 return &ExportDataOperation{
4841 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4842 pollPath: override,
4843 }
4844 }
4845
4846 // ImportDataOperation returns a new ImportDataOperation from a given name.
4847 // The name must be that of a previously created ImportDataOperation, possibly from a different process.
4848 func (c *translationGRPCClient) ImportDataOperation(name string) *ImportDataOperation {
4849 return &ImportDataOperation{
4850 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4851 }
4852 }
4853
4854 // ImportDataOperation returns a new ImportDataOperation from a given name.
4855 // The name must be that of a previously created ImportDataOperation, possibly from a different process.
4856 func (c *translationRESTClient) ImportDataOperation(name string) *ImportDataOperation {
4857 override := fmt.Sprintf("/v3/%s", name)
4858 return &ImportDataOperation{
4859 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4860 pollPath: override,
4861 }
4862 }
4863
4864 // UpdateGlossaryOperation returns a new UpdateGlossaryOperation from a given name.
4865 // The name must be that of a previously created UpdateGlossaryOperation, possibly from a different process.
4866 func (c *translationGRPCClient) UpdateGlossaryOperation(name string) *UpdateGlossaryOperation {
4867 return &UpdateGlossaryOperation{
4868 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4869 }
4870 }
4871
4872 // UpdateGlossaryOperation returns a new UpdateGlossaryOperation from a given name.
4873 // The name must be that of a previously created UpdateGlossaryOperation, possibly from a different process.
4874 func (c *translationRESTClient) UpdateGlossaryOperation(name string) *UpdateGlossaryOperation {
4875 override := fmt.Sprintf("/v3/%s", name)
4876 return &UpdateGlossaryOperation{
4877 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4878 pollPath: override,
4879 }
4880 }