1// Copyright 2021 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package automl 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 gax "github.com/googleapis/gax-go/v2" 29 "google.golang.org/api/iterator" 30 "google.golang.org/api/option" 31 "google.golang.org/api/option/internaloption" 32 gtransport "google.golang.org/api/transport/grpc" 33 automlpb "google.golang.org/genproto/googleapis/cloud/automl/v1" 34 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 35 "google.golang.org/grpc" 36 "google.golang.org/grpc/codes" 37 "google.golang.org/grpc/metadata" 38 "google.golang.org/protobuf/proto" 39) 40 41var newClientHook clientHook 42 43// CallOptions contains the retry settings for each method of Client. 44type CallOptions struct { 45 CreateDataset []gax.CallOption 46 GetDataset []gax.CallOption 47 ListDatasets []gax.CallOption 48 UpdateDataset []gax.CallOption 49 DeleteDataset []gax.CallOption 50 ImportData []gax.CallOption 51 ExportData []gax.CallOption 52 GetAnnotationSpec []gax.CallOption 53 CreateModel []gax.CallOption 54 GetModel []gax.CallOption 55 ListModels []gax.CallOption 56 DeleteModel []gax.CallOption 57 UpdateModel []gax.CallOption 58 DeployModel []gax.CallOption 59 UndeployModel []gax.CallOption 60 ExportModel []gax.CallOption 61 GetModelEvaluation []gax.CallOption 62 ListModelEvaluations []gax.CallOption 63} 64 65func defaultGRPCClientOptions() []option.ClientOption { 66 return []option.ClientOption{ 67 internaloption.WithDefaultEndpoint("automl.googleapis.com:443"), 68 internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), 69 internaloption.WithDefaultAudience("https://automl.googleapis.com/"), 70 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 71 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 72 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 73 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 74 } 75} 76 77func defaultCallOptions() *CallOptions { 78 return &CallOptions{ 79 CreateDataset: []gax.CallOption{}, 80 GetDataset: []gax.CallOption{ 81 gax.WithRetry(func() gax.Retryer { 82 return gax.OnCodes([]codes.Code{ 83 codes.DeadlineExceeded, 84 codes.Unavailable, 85 }, gax.Backoff{ 86 Initial: 100 * time.Millisecond, 87 Max: 60000 * time.Millisecond, 88 Multiplier: 1.30, 89 }) 90 }), 91 }, 92 ListDatasets: []gax.CallOption{ 93 gax.WithRetry(func() gax.Retryer { 94 return gax.OnCodes([]codes.Code{ 95 codes.DeadlineExceeded, 96 codes.Unavailable, 97 }, gax.Backoff{ 98 Initial: 100 * time.Millisecond, 99 Max: 60000 * time.Millisecond, 100 Multiplier: 1.30, 101 }) 102 }), 103 }, 104 UpdateDataset: []gax.CallOption{}, 105 DeleteDataset: []gax.CallOption{ 106 gax.WithRetry(func() gax.Retryer { 107 return gax.OnCodes([]codes.Code{ 108 codes.DeadlineExceeded, 109 codes.Unavailable, 110 }, gax.Backoff{ 111 Initial: 100 * time.Millisecond, 112 Max: 60000 * time.Millisecond, 113 Multiplier: 1.30, 114 }) 115 }), 116 }, 117 ImportData: []gax.CallOption{}, 118 ExportData: []gax.CallOption{}, 119 GetAnnotationSpec: []gax.CallOption{ 120 gax.WithRetry(func() gax.Retryer { 121 return gax.OnCodes([]codes.Code{ 122 codes.DeadlineExceeded, 123 codes.Unavailable, 124 }, gax.Backoff{ 125 Initial: 100 * time.Millisecond, 126 Max: 60000 * time.Millisecond, 127 Multiplier: 1.30, 128 }) 129 }), 130 }, 131 CreateModel: []gax.CallOption{}, 132 GetModel: []gax.CallOption{ 133 gax.WithRetry(func() gax.Retryer { 134 return gax.OnCodes([]codes.Code{ 135 codes.DeadlineExceeded, 136 codes.Unavailable, 137 }, gax.Backoff{ 138 Initial: 100 * time.Millisecond, 139 Max: 60000 * time.Millisecond, 140 Multiplier: 1.30, 141 }) 142 }), 143 }, 144 ListModels: []gax.CallOption{ 145 gax.WithRetry(func() gax.Retryer { 146 return gax.OnCodes([]codes.Code{ 147 codes.DeadlineExceeded, 148 codes.Unavailable, 149 }, gax.Backoff{ 150 Initial: 100 * time.Millisecond, 151 Max: 60000 * time.Millisecond, 152 Multiplier: 1.30, 153 }) 154 }), 155 }, 156 DeleteModel: []gax.CallOption{ 157 gax.WithRetry(func() gax.Retryer { 158 return gax.OnCodes([]codes.Code{ 159 codes.DeadlineExceeded, 160 codes.Unavailable, 161 }, gax.Backoff{ 162 Initial: 100 * time.Millisecond, 163 Max: 60000 * time.Millisecond, 164 Multiplier: 1.30, 165 }) 166 }), 167 }, 168 UpdateModel: []gax.CallOption{}, 169 DeployModel: []gax.CallOption{}, 170 UndeployModel: []gax.CallOption{}, 171 ExportModel: []gax.CallOption{}, 172 GetModelEvaluation: []gax.CallOption{ 173 gax.WithRetry(func() gax.Retryer { 174 return gax.OnCodes([]codes.Code{ 175 codes.DeadlineExceeded, 176 codes.Unavailable, 177 }, gax.Backoff{ 178 Initial: 100 * time.Millisecond, 179 Max: 60000 * time.Millisecond, 180 Multiplier: 1.30, 181 }) 182 }), 183 }, 184 ListModelEvaluations: []gax.CallOption{ 185 gax.WithRetry(func() gax.Retryer { 186 return gax.OnCodes([]codes.Code{ 187 codes.DeadlineExceeded, 188 codes.Unavailable, 189 }, gax.Backoff{ 190 Initial: 100 * time.Millisecond, 191 Max: 60000 * time.Millisecond, 192 Multiplier: 1.30, 193 }) 194 }), 195 }, 196 } 197} 198 199// internalClient is an interface that defines the methods availaible from Cloud AutoML API. 200type internalClient interface { 201 Close() error 202 setGoogleClientInfo(...string) 203 Connection() *grpc.ClientConn 204 CreateDataset(context.Context, *automlpb.CreateDatasetRequest, ...gax.CallOption) (*CreateDatasetOperation, error) 205 CreateDatasetOperation(name string) *CreateDatasetOperation 206 GetDataset(context.Context, *automlpb.GetDatasetRequest, ...gax.CallOption) (*automlpb.Dataset, error) 207 ListDatasets(context.Context, *automlpb.ListDatasetsRequest, ...gax.CallOption) *DatasetIterator 208 UpdateDataset(context.Context, *automlpb.UpdateDatasetRequest, ...gax.CallOption) (*automlpb.Dataset, error) 209 DeleteDataset(context.Context, *automlpb.DeleteDatasetRequest, ...gax.CallOption) (*DeleteDatasetOperation, error) 210 DeleteDatasetOperation(name string) *DeleteDatasetOperation 211 ImportData(context.Context, *automlpb.ImportDataRequest, ...gax.CallOption) (*ImportDataOperation, error) 212 ImportDataOperation(name string) *ImportDataOperation 213 ExportData(context.Context, *automlpb.ExportDataRequest, ...gax.CallOption) (*ExportDataOperation, error) 214 ExportDataOperation(name string) *ExportDataOperation 215 GetAnnotationSpec(context.Context, *automlpb.GetAnnotationSpecRequest, ...gax.CallOption) (*automlpb.AnnotationSpec, error) 216 CreateModel(context.Context, *automlpb.CreateModelRequest, ...gax.CallOption) (*CreateModelOperation, error) 217 CreateModelOperation(name string) *CreateModelOperation 218 GetModel(context.Context, *automlpb.GetModelRequest, ...gax.CallOption) (*automlpb.Model, error) 219 ListModels(context.Context, *automlpb.ListModelsRequest, ...gax.CallOption) *ModelIterator 220 DeleteModel(context.Context, *automlpb.DeleteModelRequest, ...gax.CallOption) (*DeleteModelOperation, error) 221 DeleteModelOperation(name string) *DeleteModelOperation 222 UpdateModel(context.Context, *automlpb.UpdateModelRequest, ...gax.CallOption) (*automlpb.Model, error) 223 DeployModel(context.Context, *automlpb.DeployModelRequest, ...gax.CallOption) (*DeployModelOperation, error) 224 DeployModelOperation(name string) *DeployModelOperation 225 UndeployModel(context.Context, *automlpb.UndeployModelRequest, ...gax.CallOption) (*UndeployModelOperation, error) 226 UndeployModelOperation(name string) *UndeployModelOperation 227 ExportModel(context.Context, *automlpb.ExportModelRequest, ...gax.CallOption) (*ExportModelOperation, error) 228 ExportModelOperation(name string) *ExportModelOperation 229 GetModelEvaluation(context.Context, *automlpb.GetModelEvaluationRequest, ...gax.CallOption) (*automlpb.ModelEvaluation, error) 230 ListModelEvaluations(context.Context, *automlpb.ListModelEvaluationsRequest, ...gax.CallOption) *ModelEvaluationIterator 231} 232 233// Client is a client for interacting with Cloud AutoML API. 234// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 235// 236// AutoML Server API. 237// 238// The resource names are assigned by the server. 239// The server never reuses names that it has created after the resources with 240// those names are deleted. 241// 242// An ID of a resource is the last element of the item’s resource name. For 243// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then 244// the id for the item is {dataset_id}. 245// 246// Currently the only supported location_id is “us-central1”. 247// 248// On any input that is documented to expect a string parameter in 249// snake_case or kebab-case, either of those cases is accepted. 250type Client struct { 251 // The internal transport-dependent client. 252 internalClient internalClient 253 254 // The call options for this service. 255 CallOptions *CallOptions 256 257 // LROClient is used internally to handle long-running operations. 258 // It is exposed so that its CallOptions can be modified if required. 259 // Users should not Close this client. 260 LROClient *lroauto.OperationsClient 261} 262 263// Wrapper methods routed to the internal client. 264 265// Close closes the connection to the API service. The user should invoke this when 266// the client is no longer required. 267func (c *Client) Close() error { 268 return c.internalClient.Close() 269} 270 271// setGoogleClientInfo sets the name and version of the application in 272// the `x-goog-api-client` header passed on each request. Intended for 273// use by Google-written clients. 274func (c *Client) setGoogleClientInfo(keyval ...string) { 275 c.internalClient.setGoogleClientInfo(keyval...) 276} 277 278// Connection returns a connection to the API service. 279// 280// Deprecated. 281func (c *Client) Connection() *grpc.ClientConn { 282 return c.internalClient.Connection() 283} 284 285// CreateDataset creates a dataset. 286func (c *Client) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { 287 return c.internalClient.CreateDataset(ctx, req, opts...) 288} 289 290// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. 291// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. 292func (c *Client) CreateDatasetOperation(name string) *CreateDatasetOperation { 293 return c.internalClient.CreateDatasetOperation(name) 294} 295 296// GetDataset gets a dataset. 297func (c *Client) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 298 return c.internalClient.GetDataset(ctx, req, opts...) 299} 300 301// ListDatasets lists datasets in a project. 302func (c *Client) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { 303 return c.internalClient.ListDatasets(ctx, req, opts...) 304} 305 306// UpdateDataset updates a dataset. 307func (c *Client) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 308 return c.internalClient.UpdateDataset(ctx, req, opts...) 309} 310 311// DeleteDataset deletes a dataset and all of its contents. 312// Returns empty response in the 313// response field when it completes, 314// and delete_details in the 315// metadata field. 316func (c *Client) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { 317 return c.internalClient.DeleteDataset(ctx, req, opts...) 318} 319 320// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. 321// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. 322func (c *Client) DeleteDatasetOperation(name string) *DeleteDatasetOperation { 323 return c.internalClient.DeleteDatasetOperation(name) 324} 325 326// ImportData imports data into a dataset. 327// For Tables this method can only be called on an empty Dataset. 328// 329// For Tables: 330// 331// A 332// schema_inference_version 333// parameter must be explicitly set. 334// Returns an empty response in the 335// response field when it completes. 336func (c *Client) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { 337 return c.internalClient.ImportData(ctx, req, opts...) 338} 339 340// ImportDataOperation returns a new ImportDataOperation from a given name. 341// The name must be that of a previously created ImportDataOperation, possibly from a different process. 342func (c *Client) ImportDataOperation(name string) *ImportDataOperation { 343 return c.internalClient.ImportDataOperation(name) 344} 345 346// ExportData exports dataset’s data to the provided output location. 347// Returns an empty response in the 348// response field when it completes. 349func (c *Client) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { 350 return c.internalClient.ExportData(ctx, req, opts...) 351} 352 353// ExportDataOperation returns a new ExportDataOperation from a given name. 354// The name must be that of a previously created ExportDataOperation, possibly from a different process. 355func (c *Client) ExportDataOperation(name string) *ExportDataOperation { 356 return c.internalClient.ExportDataOperation(name) 357} 358 359// GetAnnotationSpec gets an annotation spec. 360func (c *Client) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { 361 return c.internalClient.GetAnnotationSpec(ctx, req, opts...) 362} 363 364// CreateModel creates a model. 365// Returns a Model in the response 366// field when it completes. 367// When you create a model, several model evaluations are created for it: 368// a global evaluation, and one evaluation for each annotation spec. 369func (c *Client) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { 370 return c.internalClient.CreateModel(ctx, req, opts...) 371} 372 373// CreateModelOperation returns a new CreateModelOperation from a given name. 374// The name must be that of a previously created CreateModelOperation, possibly from a different process. 375func (c *Client) CreateModelOperation(name string) *CreateModelOperation { 376 return c.internalClient.CreateModelOperation(name) 377} 378 379// GetModel gets a model. 380func (c *Client) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 381 return c.internalClient.GetModel(ctx, req, opts...) 382} 383 384// ListModels lists models. 385func (c *Client) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { 386 return c.internalClient.ListModels(ctx, req, opts...) 387} 388 389// DeleteModel deletes a model. 390// Returns google.protobuf.Empty in the 391// response field when it completes, 392// and delete_details in the 393// metadata field. 394func (c *Client) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { 395 return c.internalClient.DeleteModel(ctx, req, opts...) 396} 397 398// DeleteModelOperation returns a new DeleteModelOperation from a given name. 399// The name must be that of a previously created DeleteModelOperation, possibly from a different process. 400func (c *Client) DeleteModelOperation(name string) *DeleteModelOperation { 401 return c.internalClient.DeleteModelOperation(name) 402} 403 404// UpdateModel updates a model. 405func (c *Client) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 406 return c.internalClient.UpdateModel(ctx, req, opts...) 407} 408 409// DeployModel deploys a model. If a model is already deployed, deploying it with the 410// same parameters has no effect. Deploying with different parametrs 411// (as e.g. changing 412// 413// node_number) 414// will reset the deployment state without pausing the model’s availability. 415// 416// Only applicable for Text Classification, Image Object Detection , Tables, and Image Segmentation; all other domains manage 417// deployment automatically. 418// 419// Returns an empty response in the 420// response field when it completes. 421func (c *Client) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 422 return c.internalClient.DeployModel(ctx, req, opts...) 423} 424 425// DeployModelOperation returns a new DeployModelOperation from a given name. 426// The name must be that of a previously created DeployModelOperation, possibly from a different process. 427func (c *Client) DeployModelOperation(name string) *DeployModelOperation { 428 return c.internalClient.DeployModelOperation(name) 429} 430 431// UndeployModel undeploys a model. If the model is not deployed this method has no effect. 432// 433// Only applicable for Text Classification, Image Object Detection and Tables; 434// all other domains manage deployment automatically. 435// 436// Returns an empty response in the 437// response field when it completes. 438func (c *Client) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 439 return c.internalClient.UndeployModel(ctx, req, opts...) 440} 441 442// UndeployModelOperation returns a new UndeployModelOperation from a given name. 443// The name must be that of a previously created UndeployModelOperation, possibly from a different process. 444func (c *Client) UndeployModelOperation(name string) *UndeployModelOperation { 445 return c.internalClient.UndeployModelOperation(name) 446} 447 448// ExportModel exports a trained, “export-able”, model to a user specified Google Cloud 449// Storage location. A model is considered export-able if and only if it has 450// an export format defined for it in 451// ModelExportOutputConfig. 452// 453// Returns an empty response in the 454// response field when it completes. 455func (c *Client) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { 456 return c.internalClient.ExportModel(ctx, req, opts...) 457} 458 459// ExportModelOperation returns a new ExportModelOperation from a given name. 460// The name must be that of a previously created ExportModelOperation, possibly from a different process. 461func (c *Client) ExportModelOperation(name string) *ExportModelOperation { 462 return c.internalClient.ExportModelOperation(name) 463} 464 465// GetModelEvaluation gets a model evaluation. 466func (c *Client) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { 467 return c.internalClient.GetModelEvaluation(ctx, req, opts...) 468} 469 470// ListModelEvaluations lists model evaluations. 471func (c *Client) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { 472 return c.internalClient.ListModelEvaluations(ctx, req, opts...) 473} 474 475// gRPCClient is a client for interacting with Cloud AutoML API over gRPC transport. 476// 477// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 478type gRPCClient struct { 479 // Connection pool of gRPC connections to the service. 480 connPool gtransport.ConnPool 481 482 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 483 disableDeadlines bool 484 485 // Points back to the CallOptions field of the containing Client 486 CallOptions **CallOptions 487 488 // The gRPC API client. 489 client automlpb.AutoMlClient 490 491 // LROClient is used internally to handle long-running operations. 492 // It is exposed so that its CallOptions can be modified if required. 493 // Users should not Close this client. 494 LROClient **lroauto.OperationsClient 495 496 // The x-goog-* metadata to be sent with each request. 497 xGoogMetadata metadata.MD 498} 499 500// NewClient creates a new auto ml client based on gRPC. 501// The returned client must be Closed when it is done being used to clean up its underlying connections. 502// 503// AutoML Server API. 504// 505// The resource names are assigned by the server. 506// The server never reuses names that it has created after the resources with 507// those names are deleted. 508// 509// An ID of a resource is the last element of the item’s resource name. For 510// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then 511// the id for the item is {dataset_id}. 512// 513// Currently the only supported location_id is “us-central1”. 514// 515// On any input that is documented to expect a string parameter in 516// snake_case or kebab-case, either of those cases is accepted. 517func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { 518 clientOpts := defaultGRPCClientOptions() 519 if newClientHook != nil { 520 hookOpts, err := newClientHook(ctx, clientHookParams{}) 521 if err != nil { 522 return nil, err 523 } 524 clientOpts = append(clientOpts, hookOpts...) 525 } 526 527 disableDeadlines, err := checkDisableDeadlines() 528 if err != nil { 529 return nil, err 530 } 531 532 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 533 if err != nil { 534 return nil, err 535 } 536 client := Client{CallOptions: defaultCallOptions()} 537 538 c := &gRPCClient{ 539 connPool: connPool, 540 disableDeadlines: disableDeadlines, 541 client: automlpb.NewAutoMlClient(connPool), 542 CallOptions: &client.CallOptions, 543 } 544 c.setGoogleClientInfo() 545 546 client.internalClient = c 547 548 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 549 if err != nil { 550 // This error "should not happen", since we are just reusing old connection pool 551 // and never actually need to dial. 552 // If this does happen, we could leak connp. However, we cannot close conn: 553 // If the user invoked the constructor with option.WithGRPCConn, 554 // we would close a connection that's still in use. 555 // TODO: investigate error conditions. 556 return nil, err 557 } 558 c.LROClient = &client.LROClient 559 return &client, nil 560} 561 562// Connection returns a connection to the API service. 563// 564// Deprecated. 565func (c *gRPCClient) Connection() *grpc.ClientConn { 566 return c.connPool.Conn() 567} 568 569// setGoogleClientInfo sets the name and version of the application in 570// the `x-goog-api-client` header passed on each request. Intended for 571// use by Google-written clients. 572func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { 573 kv := append([]string{"gl-go", versionGo()}, keyval...) 574 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 575 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 576} 577 578// Close closes the connection to the API service. The user should invoke this when 579// the client is no longer required. 580func (c *gRPCClient) Close() error { 581 return c.connPool.Close() 582} 583 584func (c *gRPCClient) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { 585 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 586 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 587 defer cancel() 588 ctx = cctx 589 } 590 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 591 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 592 opts = append((*c.CallOptions).CreateDataset[0:len((*c.CallOptions).CreateDataset):len((*c.CallOptions).CreateDataset)], opts...) 593 var resp *longrunningpb.Operation 594 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 595 var err error 596 resp, err = c.client.CreateDataset(ctx, req, settings.GRPC...) 597 return err 598 }, opts...) 599 if err != nil { 600 return nil, err 601 } 602 return &CreateDatasetOperation{ 603 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 604 }, nil 605} 606 607func (c *gRPCClient) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 608 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 609 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 610 defer cancel() 611 ctx = cctx 612 } 613 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 614 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 615 opts = append((*c.CallOptions).GetDataset[0:len((*c.CallOptions).GetDataset):len((*c.CallOptions).GetDataset)], opts...) 616 var resp *automlpb.Dataset 617 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 618 var err error 619 resp, err = c.client.GetDataset(ctx, req, settings.GRPC...) 620 return err 621 }, opts...) 622 if err != nil { 623 return nil, err 624 } 625 return resp, nil 626} 627 628func (c *gRPCClient) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { 629 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 630 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 631 opts = append((*c.CallOptions).ListDatasets[0:len((*c.CallOptions).ListDatasets):len((*c.CallOptions).ListDatasets)], opts...) 632 it := &DatasetIterator{} 633 req = proto.Clone(req).(*automlpb.ListDatasetsRequest) 634 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Dataset, string, error) { 635 var resp *automlpb.ListDatasetsResponse 636 req.PageToken = pageToken 637 if pageSize > math.MaxInt32 { 638 req.PageSize = math.MaxInt32 639 } else { 640 req.PageSize = int32(pageSize) 641 } 642 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 643 var err error 644 resp, err = c.client.ListDatasets(ctx, req, settings.GRPC...) 645 return err 646 }, opts...) 647 if err != nil { 648 return nil, "", err 649 } 650 651 it.Response = resp 652 return resp.GetDatasets(), resp.GetNextPageToken(), nil 653 } 654 fetch := func(pageSize int, pageToken string) (string, error) { 655 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 656 if err != nil { 657 return "", err 658 } 659 it.items = append(it.items, items...) 660 return nextPageToken, nil 661 } 662 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 663 it.pageInfo.MaxSize = int(req.GetPageSize()) 664 it.pageInfo.Token = req.GetPageToken() 665 return it 666} 667 668func (c *gRPCClient) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 669 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 670 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 671 defer cancel() 672 ctx = cctx 673 } 674 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "dataset.name", url.QueryEscape(req.GetDataset().GetName()))) 675 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 676 opts = append((*c.CallOptions).UpdateDataset[0:len((*c.CallOptions).UpdateDataset):len((*c.CallOptions).UpdateDataset)], opts...) 677 var resp *automlpb.Dataset 678 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 679 var err error 680 resp, err = c.client.UpdateDataset(ctx, req, settings.GRPC...) 681 return err 682 }, opts...) 683 if err != nil { 684 return nil, err 685 } 686 return resp, nil 687} 688 689func (c *gRPCClient) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { 690 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 691 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 692 defer cancel() 693 ctx = cctx 694 } 695 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 696 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 697 opts = append((*c.CallOptions).DeleteDataset[0:len((*c.CallOptions).DeleteDataset):len((*c.CallOptions).DeleteDataset)], opts...) 698 var resp *longrunningpb.Operation 699 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 700 var err error 701 resp, err = c.client.DeleteDataset(ctx, req, settings.GRPC...) 702 return err 703 }, opts...) 704 if err != nil { 705 return nil, err 706 } 707 return &DeleteDatasetOperation{ 708 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 709 }, nil 710} 711 712func (c *gRPCClient) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { 713 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 714 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 715 defer cancel() 716 ctx = cctx 717 } 718 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 719 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 720 opts = append((*c.CallOptions).ImportData[0:len((*c.CallOptions).ImportData):len((*c.CallOptions).ImportData)], opts...) 721 var resp *longrunningpb.Operation 722 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 723 var err error 724 resp, err = c.client.ImportData(ctx, req, settings.GRPC...) 725 return err 726 }, opts...) 727 if err != nil { 728 return nil, err 729 } 730 return &ImportDataOperation{ 731 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 732 }, nil 733} 734 735func (c *gRPCClient) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { 736 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 737 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 738 defer cancel() 739 ctx = cctx 740 } 741 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 742 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 743 opts = append((*c.CallOptions).ExportData[0:len((*c.CallOptions).ExportData):len((*c.CallOptions).ExportData)], opts...) 744 var resp *longrunningpb.Operation 745 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 746 var err error 747 resp, err = c.client.ExportData(ctx, req, settings.GRPC...) 748 return err 749 }, opts...) 750 if err != nil { 751 return nil, err 752 } 753 return &ExportDataOperation{ 754 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 755 }, nil 756} 757 758func (c *gRPCClient) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { 759 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 760 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 761 defer cancel() 762 ctx = cctx 763 } 764 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 765 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 766 opts = append((*c.CallOptions).GetAnnotationSpec[0:len((*c.CallOptions).GetAnnotationSpec):len((*c.CallOptions).GetAnnotationSpec)], opts...) 767 var resp *automlpb.AnnotationSpec 768 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 769 var err error 770 resp, err = c.client.GetAnnotationSpec(ctx, req, settings.GRPC...) 771 return err 772 }, opts...) 773 if err != nil { 774 return nil, err 775 } 776 return resp, nil 777} 778 779func (c *gRPCClient) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { 780 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 781 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 782 defer cancel() 783 ctx = cctx 784 } 785 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 786 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 787 opts = append((*c.CallOptions).CreateModel[0:len((*c.CallOptions).CreateModel):len((*c.CallOptions).CreateModel)], opts...) 788 var resp *longrunningpb.Operation 789 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 790 var err error 791 resp, err = c.client.CreateModel(ctx, req, settings.GRPC...) 792 return err 793 }, opts...) 794 if err != nil { 795 return nil, err 796 } 797 return &CreateModelOperation{ 798 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 799 }, nil 800} 801 802func (c *gRPCClient) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 803 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 804 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 805 defer cancel() 806 ctx = cctx 807 } 808 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 809 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 810 opts = append((*c.CallOptions).GetModel[0:len((*c.CallOptions).GetModel):len((*c.CallOptions).GetModel)], opts...) 811 var resp *automlpb.Model 812 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 813 var err error 814 resp, err = c.client.GetModel(ctx, req, settings.GRPC...) 815 return err 816 }, opts...) 817 if err != nil { 818 return nil, err 819 } 820 return resp, nil 821} 822 823func (c *gRPCClient) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { 824 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 825 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 826 opts = append((*c.CallOptions).ListModels[0:len((*c.CallOptions).ListModels):len((*c.CallOptions).ListModels)], opts...) 827 it := &ModelIterator{} 828 req = proto.Clone(req).(*automlpb.ListModelsRequest) 829 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Model, string, error) { 830 var resp *automlpb.ListModelsResponse 831 req.PageToken = pageToken 832 if pageSize > math.MaxInt32 { 833 req.PageSize = math.MaxInt32 834 } else { 835 req.PageSize = int32(pageSize) 836 } 837 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 838 var err error 839 resp, err = c.client.ListModels(ctx, req, settings.GRPC...) 840 return err 841 }, opts...) 842 if err != nil { 843 return nil, "", err 844 } 845 846 it.Response = resp 847 return resp.GetModel(), resp.GetNextPageToken(), nil 848 } 849 fetch := func(pageSize int, pageToken string) (string, error) { 850 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 851 if err != nil { 852 return "", err 853 } 854 it.items = append(it.items, items...) 855 return nextPageToken, nil 856 } 857 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 858 it.pageInfo.MaxSize = int(req.GetPageSize()) 859 it.pageInfo.Token = req.GetPageToken() 860 return it 861} 862 863func (c *gRPCClient) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { 864 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 865 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 866 defer cancel() 867 ctx = cctx 868 } 869 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 870 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 871 opts = append((*c.CallOptions).DeleteModel[0:len((*c.CallOptions).DeleteModel):len((*c.CallOptions).DeleteModel)], opts...) 872 var resp *longrunningpb.Operation 873 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 874 var err error 875 resp, err = c.client.DeleteModel(ctx, req, settings.GRPC...) 876 return err 877 }, opts...) 878 if err != nil { 879 return nil, err 880 } 881 return &DeleteModelOperation{ 882 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 883 }, nil 884} 885 886func (c *gRPCClient) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 887 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 888 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 889 defer cancel() 890 ctx = cctx 891 } 892 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "model.name", url.QueryEscape(req.GetModel().GetName()))) 893 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 894 opts = append((*c.CallOptions).UpdateModel[0:len((*c.CallOptions).UpdateModel):len((*c.CallOptions).UpdateModel)], opts...) 895 var resp *automlpb.Model 896 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 897 var err error 898 resp, err = c.client.UpdateModel(ctx, req, settings.GRPC...) 899 return err 900 }, opts...) 901 if err != nil { 902 return nil, err 903 } 904 return resp, nil 905} 906 907func (c *gRPCClient) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 908 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 909 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 910 defer cancel() 911 ctx = cctx 912 } 913 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 914 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 915 opts = append((*c.CallOptions).DeployModel[0:len((*c.CallOptions).DeployModel):len((*c.CallOptions).DeployModel)], opts...) 916 var resp *longrunningpb.Operation 917 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 918 var err error 919 resp, err = c.client.DeployModel(ctx, req, settings.GRPC...) 920 return err 921 }, opts...) 922 if err != nil { 923 return nil, err 924 } 925 return &DeployModelOperation{ 926 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 927 }, nil 928} 929 930func (c *gRPCClient) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 931 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 932 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 933 defer cancel() 934 ctx = cctx 935 } 936 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 937 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 938 opts = append((*c.CallOptions).UndeployModel[0:len((*c.CallOptions).UndeployModel):len((*c.CallOptions).UndeployModel)], opts...) 939 var resp *longrunningpb.Operation 940 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 941 var err error 942 resp, err = c.client.UndeployModel(ctx, req, settings.GRPC...) 943 return err 944 }, opts...) 945 if err != nil { 946 return nil, err 947 } 948 return &UndeployModelOperation{ 949 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 950 }, nil 951} 952 953func (c *gRPCClient) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { 954 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 955 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 956 defer cancel() 957 ctx = cctx 958 } 959 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 960 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 961 opts = append((*c.CallOptions).ExportModel[0:len((*c.CallOptions).ExportModel):len((*c.CallOptions).ExportModel)], opts...) 962 var resp *longrunningpb.Operation 963 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 964 var err error 965 resp, err = c.client.ExportModel(ctx, req, settings.GRPC...) 966 return err 967 }, opts...) 968 if err != nil { 969 return nil, err 970 } 971 return &ExportModelOperation{ 972 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 973 }, nil 974} 975 976func (c *gRPCClient) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { 977 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 978 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 979 defer cancel() 980 ctx = cctx 981 } 982 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 983 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 984 opts = append((*c.CallOptions).GetModelEvaluation[0:len((*c.CallOptions).GetModelEvaluation):len((*c.CallOptions).GetModelEvaluation)], opts...) 985 var resp *automlpb.ModelEvaluation 986 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 987 var err error 988 resp, err = c.client.GetModelEvaluation(ctx, req, settings.GRPC...) 989 return err 990 }, opts...) 991 if err != nil { 992 return nil, err 993 } 994 return resp, nil 995} 996 997func (c *gRPCClient) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { 998 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 999 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 1000 opts = append((*c.CallOptions).ListModelEvaluations[0:len((*c.CallOptions).ListModelEvaluations):len((*c.CallOptions).ListModelEvaluations)], opts...) 1001 it := &ModelEvaluationIterator{} 1002 req = proto.Clone(req).(*automlpb.ListModelEvaluationsRequest) 1003 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.ModelEvaluation, string, error) { 1004 var resp *automlpb.ListModelEvaluationsResponse 1005 req.PageToken = pageToken 1006 if pageSize > math.MaxInt32 { 1007 req.PageSize = math.MaxInt32 1008 } else { 1009 req.PageSize = int32(pageSize) 1010 } 1011 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1012 var err error 1013 resp, err = c.client.ListModelEvaluations(ctx, req, settings.GRPC...) 1014 return err 1015 }, opts...) 1016 if err != nil { 1017 return nil, "", err 1018 } 1019 1020 it.Response = resp 1021 return resp.GetModelEvaluation(), resp.GetNextPageToken(), nil 1022 } 1023 fetch := func(pageSize int, pageToken string) (string, error) { 1024 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1025 if err != nil { 1026 return "", err 1027 } 1028 it.items = append(it.items, items...) 1029 return nextPageToken, nil 1030 } 1031 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1032 it.pageInfo.MaxSize = int(req.GetPageSize()) 1033 it.pageInfo.Token = req.GetPageToken() 1034 return it 1035} 1036 1037// CreateDatasetOperation manages a long-running operation from CreateDataset. 1038type CreateDatasetOperation struct { 1039 lro *longrunning.Operation 1040} 1041 1042// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. 1043// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. 1044func (c *gRPCClient) CreateDatasetOperation(name string) *CreateDatasetOperation { 1045 return &CreateDatasetOperation{ 1046 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1047 } 1048} 1049 1050// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1051// 1052// See documentation of Poll for error-handling information. 1053func (op *CreateDatasetOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*automlpb.Dataset, error) { 1054 var resp automlpb.Dataset 1055 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 1056 return nil, err 1057 } 1058 return &resp, nil 1059} 1060 1061// Poll fetches the latest state of the long-running operation. 1062// 1063// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1064// 1065// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1066// the operation has completed with failure, the error is returned and op.Done will return true. 1067// If Poll succeeds and the operation has completed successfully, 1068// op.Done will return true, and the response of the operation is returned. 1069// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1070func (op *CreateDatasetOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*automlpb.Dataset, error) { 1071 var resp automlpb.Dataset 1072 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 1073 return nil, err 1074 } 1075 if !op.Done() { 1076 return nil, nil 1077 } 1078 return &resp, nil 1079} 1080 1081// Metadata returns metadata associated with the long-running operation. 1082// Metadata itself does not contact the server, but Poll does. 1083// To get the latest metadata, call this method after a successful call to Poll. 1084// If the metadata is not available, the returned metadata and error are both nil. 1085func (op *CreateDatasetOperation) Metadata() (*automlpb.OperationMetadata, error) { 1086 var meta automlpb.OperationMetadata 1087 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1088 return nil, nil 1089 } else if err != nil { 1090 return nil, err 1091 } 1092 return &meta, nil 1093} 1094 1095// Done reports whether the long-running operation has completed. 1096func (op *CreateDatasetOperation) Done() bool { 1097 return op.lro.Done() 1098} 1099 1100// Name returns the name of the long-running operation. 1101// The name is assigned by the server and is unique within the service from which the operation is created. 1102func (op *CreateDatasetOperation) Name() string { 1103 return op.lro.Name() 1104} 1105 1106// CreateModelOperation manages a long-running operation from CreateModel. 1107type CreateModelOperation struct { 1108 lro *longrunning.Operation 1109} 1110 1111// CreateModelOperation returns a new CreateModelOperation from a given name. 1112// The name must be that of a previously created CreateModelOperation, possibly from a different process. 1113func (c *gRPCClient) CreateModelOperation(name string) *CreateModelOperation { 1114 return &CreateModelOperation{ 1115 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1116 } 1117} 1118 1119// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1120// 1121// See documentation of Poll for error-handling information. 1122func (op *CreateModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*automlpb.Model, error) { 1123 var resp automlpb.Model 1124 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 1125 return nil, err 1126 } 1127 return &resp, nil 1128} 1129 1130// Poll fetches the latest state of the long-running operation. 1131// 1132// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1133// 1134// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1135// the operation has completed with failure, the error is returned and op.Done will return true. 1136// If Poll succeeds and the operation has completed successfully, 1137// op.Done will return true, and the response of the operation is returned. 1138// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1139func (op *CreateModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*automlpb.Model, error) { 1140 var resp automlpb.Model 1141 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 1142 return nil, err 1143 } 1144 if !op.Done() { 1145 return nil, nil 1146 } 1147 return &resp, nil 1148} 1149 1150// Metadata returns metadata associated with the long-running operation. 1151// Metadata itself does not contact the server, but Poll does. 1152// To get the latest metadata, call this method after a successful call to Poll. 1153// If the metadata is not available, the returned metadata and error are both nil. 1154func (op *CreateModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1155 var meta automlpb.OperationMetadata 1156 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1157 return nil, nil 1158 } else if err != nil { 1159 return nil, err 1160 } 1161 return &meta, nil 1162} 1163 1164// Done reports whether the long-running operation has completed. 1165func (op *CreateModelOperation) Done() bool { 1166 return op.lro.Done() 1167} 1168 1169// Name returns the name of the long-running operation. 1170// The name is assigned by the server and is unique within the service from which the operation is created. 1171func (op *CreateModelOperation) Name() string { 1172 return op.lro.Name() 1173} 1174 1175// DeleteDatasetOperation manages a long-running operation from DeleteDataset. 1176type DeleteDatasetOperation struct { 1177 lro *longrunning.Operation 1178} 1179 1180// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. 1181// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. 1182func (c *gRPCClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation { 1183 return &DeleteDatasetOperation{ 1184 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1185 } 1186} 1187 1188// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1189// 1190// See documentation of Poll for error-handling information. 1191func (op *DeleteDatasetOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1192 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1193} 1194 1195// Poll fetches the latest state of the long-running operation. 1196// 1197// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1198// 1199// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1200// the operation has completed with failure, the error is returned and op.Done will return true. 1201// If Poll succeeds and the operation has completed successfully, 1202// op.Done will return true, and the response of the operation is returned. 1203// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1204func (op *DeleteDatasetOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1205 return op.lro.Poll(ctx, nil, opts...) 1206} 1207 1208// Metadata returns metadata associated with the long-running operation. 1209// Metadata itself does not contact the server, but Poll does. 1210// To get the latest metadata, call this method after a successful call to Poll. 1211// If the metadata is not available, the returned metadata and error are both nil. 1212func (op *DeleteDatasetOperation) Metadata() (*automlpb.OperationMetadata, error) { 1213 var meta automlpb.OperationMetadata 1214 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1215 return nil, nil 1216 } else if err != nil { 1217 return nil, err 1218 } 1219 return &meta, nil 1220} 1221 1222// Done reports whether the long-running operation has completed. 1223func (op *DeleteDatasetOperation) Done() bool { 1224 return op.lro.Done() 1225} 1226 1227// Name returns the name of the long-running operation. 1228// The name is assigned by the server and is unique within the service from which the operation is created. 1229func (op *DeleteDatasetOperation) Name() string { 1230 return op.lro.Name() 1231} 1232 1233// DeleteModelOperation manages a long-running operation from DeleteModel. 1234type DeleteModelOperation struct { 1235 lro *longrunning.Operation 1236} 1237 1238// DeleteModelOperation returns a new DeleteModelOperation from a given name. 1239// The name must be that of a previously created DeleteModelOperation, possibly from a different process. 1240func (c *gRPCClient) DeleteModelOperation(name string) *DeleteModelOperation { 1241 return &DeleteModelOperation{ 1242 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1243 } 1244} 1245 1246// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1247// 1248// See documentation of Poll for error-handling information. 1249func (op *DeleteModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1250 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1251} 1252 1253// Poll fetches the latest state of the long-running operation. 1254// 1255// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1256// 1257// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1258// the operation has completed with failure, the error is returned and op.Done will return true. 1259// If Poll succeeds and the operation has completed successfully, 1260// op.Done will return true, and the response of the operation is returned. 1261// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1262func (op *DeleteModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1263 return op.lro.Poll(ctx, nil, opts...) 1264} 1265 1266// Metadata returns metadata associated with the long-running operation. 1267// Metadata itself does not contact the server, but Poll does. 1268// To get the latest metadata, call this method after a successful call to Poll. 1269// If the metadata is not available, the returned metadata and error are both nil. 1270func (op *DeleteModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1271 var meta automlpb.OperationMetadata 1272 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1273 return nil, nil 1274 } else if err != nil { 1275 return nil, err 1276 } 1277 return &meta, nil 1278} 1279 1280// Done reports whether the long-running operation has completed. 1281func (op *DeleteModelOperation) Done() bool { 1282 return op.lro.Done() 1283} 1284 1285// Name returns the name of the long-running operation. 1286// The name is assigned by the server and is unique within the service from which the operation is created. 1287func (op *DeleteModelOperation) Name() string { 1288 return op.lro.Name() 1289} 1290 1291// DeployModelOperation manages a long-running operation from DeployModel. 1292type DeployModelOperation struct { 1293 lro *longrunning.Operation 1294} 1295 1296// DeployModelOperation returns a new DeployModelOperation from a given name. 1297// The name must be that of a previously created DeployModelOperation, possibly from a different process. 1298func (c *gRPCClient) DeployModelOperation(name string) *DeployModelOperation { 1299 return &DeployModelOperation{ 1300 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1301 } 1302} 1303 1304// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1305// 1306// See documentation of Poll for error-handling information. 1307func (op *DeployModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1308 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1309} 1310 1311// Poll fetches the latest state of the long-running operation. 1312// 1313// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1314// 1315// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1316// the operation has completed with failure, the error is returned and op.Done will return true. 1317// If Poll succeeds and the operation has completed successfully, 1318// op.Done will return true, and the response of the operation is returned. 1319// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1320func (op *DeployModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1321 return op.lro.Poll(ctx, nil, opts...) 1322} 1323 1324// Metadata returns metadata associated with the long-running operation. 1325// Metadata itself does not contact the server, but Poll does. 1326// To get the latest metadata, call this method after a successful call to Poll. 1327// If the metadata is not available, the returned metadata and error are both nil. 1328func (op *DeployModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1329 var meta automlpb.OperationMetadata 1330 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1331 return nil, nil 1332 } else if err != nil { 1333 return nil, err 1334 } 1335 return &meta, nil 1336} 1337 1338// Done reports whether the long-running operation has completed. 1339func (op *DeployModelOperation) Done() bool { 1340 return op.lro.Done() 1341} 1342 1343// Name returns the name of the long-running operation. 1344// The name is assigned by the server and is unique within the service from which the operation is created. 1345func (op *DeployModelOperation) Name() string { 1346 return op.lro.Name() 1347} 1348 1349// ExportDataOperation manages a long-running operation from ExportData. 1350type ExportDataOperation struct { 1351 lro *longrunning.Operation 1352} 1353 1354// ExportDataOperation returns a new ExportDataOperation from a given name. 1355// The name must be that of a previously created ExportDataOperation, possibly from a different process. 1356func (c *gRPCClient) ExportDataOperation(name string) *ExportDataOperation { 1357 return &ExportDataOperation{ 1358 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1359 } 1360} 1361 1362// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1363// 1364// See documentation of Poll for error-handling information. 1365func (op *ExportDataOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1366 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1367} 1368 1369// Poll fetches the latest state of the long-running operation. 1370// 1371// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1372// 1373// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1374// the operation has completed with failure, the error is returned and op.Done will return true. 1375// If Poll succeeds and the operation has completed successfully, 1376// op.Done will return true, and the response of the operation is returned. 1377// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1378func (op *ExportDataOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1379 return op.lro.Poll(ctx, nil, opts...) 1380} 1381 1382// Metadata returns metadata associated with the long-running operation. 1383// Metadata itself does not contact the server, but Poll does. 1384// To get the latest metadata, call this method after a successful call to Poll. 1385// If the metadata is not available, the returned metadata and error are both nil. 1386func (op *ExportDataOperation) Metadata() (*automlpb.OperationMetadata, error) { 1387 var meta automlpb.OperationMetadata 1388 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1389 return nil, nil 1390 } else if err != nil { 1391 return nil, err 1392 } 1393 return &meta, nil 1394} 1395 1396// Done reports whether the long-running operation has completed. 1397func (op *ExportDataOperation) Done() bool { 1398 return op.lro.Done() 1399} 1400 1401// Name returns the name of the long-running operation. 1402// The name is assigned by the server and is unique within the service from which the operation is created. 1403func (op *ExportDataOperation) Name() string { 1404 return op.lro.Name() 1405} 1406 1407// ExportModelOperation manages a long-running operation from ExportModel. 1408type ExportModelOperation struct { 1409 lro *longrunning.Operation 1410} 1411 1412// ExportModelOperation returns a new ExportModelOperation from a given name. 1413// The name must be that of a previously created ExportModelOperation, possibly from a different process. 1414func (c *gRPCClient) ExportModelOperation(name string) *ExportModelOperation { 1415 return &ExportModelOperation{ 1416 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1417 } 1418} 1419 1420// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1421// 1422// See documentation of Poll for error-handling information. 1423func (op *ExportModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1424 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1425} 1426 1427// Poll fetches the latest state of the long-running operation. 1428// 1429// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1430// 1431// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1432// the operation has completed with failure, the error is returned and op.Done will return true. 1433// If Poll succeeds and the operation has completed successfully, 1434// op.Done will return true, and the response of the operation is returned. 1435// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1436func (op *ExportModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1437 return op.lro.Poll(ctx, nil, opts...) 1438} 1439 1440// Metadata returns metadata associated with the long-running operation. 1441// Metadata itself does not contact the server, but Poll does. 1442// To get the latest metadata, call this method after a successful call to Poll. 1443// If the metadata is not available, the returned metadata and error are both nil. 1444func (op *ExportModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1445 var meta automlpb.OperationMetadata 1446 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1447 return nil, nil 1448 } else if err != nil { 1449 return nil, err 1450 } 1451 return &meta, nil 1452} 1453 1454// Done reports whether the long-running operation has completed. 1455func (op *ExportModelOperation) Done() bool { 1456 return op.lro.Done() 1457} 1458 1459// Name returns the name of the long-running operation. 1460// The name is assigned by the server and is unique within the service from which the operation is created. 1461func (op *ExportModelOperation) Name() string { 1462 return op.lro.Name() 1463} 1464 1465// ImportDataOperation manages a long-running operation from ImportData. 1466type ImportDataOperation struct { 1467 lro *longrunning.Operation 1468} 1469 1470// ImportDataOperation returns a new ImportDataOperation from a given name. 1471// The name must be that of a previously created ImportDataOperation, possibly from a different process. 1472func (c *gRPCClient) ImportDataOperation(name string) *ImportDataOperation { 1473 return &ImportDataOperation{ 1474 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1475 } 1476} 1477 1478// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1479// 1480// See documentation of Poll for error-handling information. 1481func (op *ImportDataOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1482 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1483} 1484 1485// Poll fetches the latest state of the long-running operation. 1486// 1487// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1488// 1489// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1490// the operation has completed with failure, the error is returned and op.Done will return true. 1491// If Poll succeeds and the operation has completed successfully, 1492// op.Done will return true, and the response of the operation is returned. 1493// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1494func (op *ImportDataOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1495 return op.lro.Poll(ctx, nil, opts...) 1496} 1497 1498// Metadata returns metadata associated with the long-running operation. 1499// Metadata itself does not contact the server, but Poll does. 1500// To get the latest metadata, call this method after a successful call to Poll. 1501// If the metadata is not available, the returned metadata and error are both nil. 1502func (op *ImportDataOperation) Metadata() (*automlpb.OperationMetadata, error) { 1503 var meta automlpb.OperationMetadata 1504 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1505 return nil, nil 1506 } else if err != nil { 1507 return nil, err 1508 } 1509 return &meta, nil 1510} 1511 1512// Done reports whether the long-running operation has completed. 1513func (op *ImportDataOperation) Done() bool { 1514 return op.lro.Done() 1515} 1516 1517// Name returns the name of the long-running operation. 1518// The name is assigned by the server and is unique within the service from which the operation is created. 1519func (op *ImportDataOperation) Name() string { 1520 return op.lro.Name() 1521} 1522 1523// UndeployModelOperation manages a long-running operation from UndeployModel. 1524type UndeployModelOperation struct { 1525 lro *longrunning.Operation 1526} 1527 1528// UndeployModelOperation returns a new UndeployModelOperation from a given name. 1529// The name must be that of a previously created UndeployModelOperation, possibly from a different process. 1530func (c *gRPCClient) UndeployModelOperation(name string) *UndeployModelOperation { 1531 return &UndeployModelOperation{ 1532 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1533 } 1534} 1535 1536// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1537// 1538// See documentation of Poll for error-handling information. 1539func (op *UndeployModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1540 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1541} 1542 1543// Poll fetches the latest state of the long-running operation. 1544// 1545// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1546// 1547// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1548// the operation has completed with failure, the error is returned and op.Done will return true. 1549// If Poll succeeds and the operation has completed successfully, 1550// op.Done will return true, and the response of the operation is returned. 1551// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1552func (op *UndeployModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1553 return op.lro.Poll(ctx, nil, opts...) 1554} 1555 1556// Metadata returns metadata associated with the long-running operation. 1557// Metadata itself does not contact the server, but Poll does. 1558// To get the latest metadata, call this method after a successful call to Poll. 1559// If the metadata is not available, the returned metadata and error are both nil. 1560func (op *UndeployModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1561 var meta automlpb.OperationMetadata 1562 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1563 return nil, nil 1564 } else if err != nil { 1565 return nil, err 1566 } 1567 return &meta, nil 1568} 1569 1570// Done reports whether the long-running operation has completed. 1571func (op *UndeployModelOperation) Done() bool { 1572 return op.lro.Done() 1573} 1574 1575// Name returns the name of the long-running operation. 1576// The name is assigned by the server and is unique within the service from which the operation is created. 1577func (op *UndeployModelOperation) Name() string { 1578 return op.lro.Name() 1579} 1580 1581// DatasetIterator manages a stream of *automlpb.Dataset. 1582type DatasetIterator struct { 1583 items []*automlpb.Dataset 1584 pageInfo *iterator.PageInfo 1585 nextFunc func() error 1586 1587 // Response is the raw response for the current page. 1588 // It must be cast to the RPC response type. 1589 // Calling Next() or InternalFetch() updates this value. 1590 Response interface{} 1591 1592 // InternalFetch is for use by the Google Cloud Libraries only. 1593 // It is not part of the stable interface of this package. 1594 // 1595 // InternalFetch returns results from a single call to the underlying RPC. 1596 // The number of results is no greater than pageSize. 1597 // If there are no more results, nextPageToken is empty and err is nil. 1598 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.Dataset, nextPageToken string, err error) 1599} 1600 1601// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1602func (it *DatasetIterator) PageInfo() *iterator.PageInfo { 1603 return it.pageInfo 1604} 1605 1606// Next returns the next result. Its second return value is iterator.Done if there are no more 1607// results. Once Next returns Done, all subsequent calls will return Done. 1608func (it *DatasetIterator) Next() (*automlpb.Dataset, error) { 1609 var item *automlpb.Dataset 1610 if err := it.nextFunc(); err != nil { 1611 return item, err 1612 } 1613 item = it.items[0] 1614 it.items = it.items[1:] 1615 return item, nil 1616} 1617 1618func (it *DatasetIterator) bufLen() int { 1619 return len(it.items) 1620} 1621 1622func (it *DatasetIterator) takeBuf() interface{} { 1623 b := it.items 1624 it.items = nil 1625 return b 1626} 1627 1628// ModelEvaluationIterator manages a stream of *automlpb.ModelEvaluation. 1629type ModelEvaluationIterator struct { 1630 items []*automlpb.ModelEvaluation 1631 pageInfo *iterator.PageInfo 1632 nextFunc func() error 1633 1634 // Response is the raw response for the current page. 1635 // It must be cast to the RPC response type. 1636 // Calling Next() or InternalFetch() updates this value. 1637 Response interface{} 1638 1639 // InternalFetch is for use by the Google Cloud Libraries only. 1640 // It is not part of the stable interface of this package. 1641 // 1642 // InternalFetch returns results from a single call to the underlying RPC. 1643 // The number of results is no greater than pageSize. 1644 // If there are no more results, nextPageToken is empty and err is nil. 1645 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.ModelEvaluation, nextPageToken string, err error) 1646} 1647 1648// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1649func (it *ModelEvaluationIterator) PageInfo() *iterator.PageInfo { 1650 return it.pageInfo 1651} 1652 1653// Next returns the next result. Its second return value is iterator.Done if there are no more 1654// results. Once Next returns Done, all subsequent calls will return Done. 1655func (it *ModelEvaluationIterator) Next() (*automlpb.ModelEvaluation, error) { 1656 var item *automlpb.ModelEvaluation 1657 if err := it.nextFunc(); err != nil { 1658 return item, err 1659 } 1660 item = it.items[0] 1661 it.items = it.items[1:] 1662 return item, nil 1663} 1664 1665func (it *ModelEvaluationIterator) bufLen() int { 1666 return len(it.items) 1667} 1668 1669func (it *ModelEvaluationIterator) takeBuf() interface{} { 1670 b := it.items 1671 it.items = nil 1672 return b 1673} 1674 1675// ModelIterator manages a stream of *automlpb.Model. 1676type ModelIterator struct { 1677 items []*automlpb.Model 1678 pageInfo *iterator.PageInfo 1679 nextFunc func() error 1680 1681 // Response is the raw response for the current page. 1682 // It must be cast to the RPC response type. 1683 // Calling Next() or InternalFetch() updates this value. 1684 Response interface{} 1685 1686 // InternalFetch is for use by the Google Cloud Libraries only. 1687 // It is not part of the stable interface of this package. 1688 // 1689 // InternalFetch returns results from a single call to the underlying RPC. 1690 // The number of results is no greater than pageSize. 1691 // If there are no more results, nextPageToken is empty and err is nil. 1692 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.Model, nextPageToken string, err error) 1693} 1694 1695// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1696func (it *ModelIterator) PageInfo() *iterator.PageInfo { 1697 return it.pageInfo 1698} 1699 1700// Next returns the next result. Its second return value is iterator.Done if there are no more 1701// results. Once Next returns Done, all subsequent calls will return Done. 1702func (it *ModelIterator) Next() (*automlpb.Model, error) { 1703 var item *automlpb.Model 1704 if err := it.nextFunc(); err != nil { 1705 return item, err 1706 } 1707 item = it.items[0] 1708 it.items = it.items[1:] 1709 return item, nil 1710} 1711 1712func (it *ModelIterator) bufLen() int { 1713 return len(it.items) 1714} 1715 1716func (it *ModelIterator) takeBuf() interface{} { 1717 b := it.items 1718 it.items = nil 1719 return b 1720} 1721