cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/index_endpoint_client_example_test.go (about)

     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 aiplatform_test
    18  
    19  import (
    20  	"context"
    21  
    22  	aiplatform "cloud.google.com/go/aiplatform/apiv1beta1"
    23  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb"
    24  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    25  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    26  	"google.golang.org/api/iterator"
    27  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    28  )
    29  
    30  func ExampleNewIndexEndpointClient() {
    31  	ctx := context.Background()
    32  	// This snippet has been automatically generated and should be regarded as a code template only.
    33  	// It will require modifications to work:
    34  	// - It may require correct/in-range values for request initialization.
    35  	// - It may require specifying regional endpoints when creating the service client as shown in:
    36  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    37  	c, err := aiplatform.NewIndexEndpointClient(ctx)
    38  	if err != nil {
    39  		// TODO: Handle error.
    40  	}
    41  	defer c.Close()
    42  
    43  	// TODO: Use client.
    44  	_ = c
    45  }
    46  
    47  func ExampleNewIndexEndpointRESTClient() {
    48  	ctx := context.Background()
    49  	// This snippet has been automatically generated and should be regarded as a code template only.
    50  	// It will require modifications to work:
    51  	// - It may require correct/in-range values for request initialization.
    52  	// - It may require specifying regional endpoints when creating the service client as shown in:
    53  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    54  	c, err := aiplatform.NewIndexEndpointRESTClient(ctx)
    55  	if err != nil {
    56  		// TODO: Handle error.
    57  	}
    58  	defer c.Close()
    59  
    60  	// TODO: Use client.
    61  	_ = c
    62  }
    63  
    64  func ExampleIndexEndpointClient_CreateIndexEndpoint() {
    65  	ctx := context.Background()
    66  	// This snippet has been automatically generated and should be regarded as a code template only.
    67  	// It will require modifications to work:
    68  	// - It may require correct/in-range values for request initialization.
    69  	// - It may require specifying regional endpoints when creating the service client as shown in:
    70  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    71  	c, err := aiplatform.NewIndexEndpointClient(ctx)
    72  	if err != nil {
    73  		// TODO: Handle error.
    74  	}
    75  	defer c.Close()
    76  
    77  	req := &aiplatformpb.CreateIndexEndpointRequest{
    78  		// TODO: Fill request struct fields.
    79  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateIndexEndpointRequest.
    80  	}
    81  	op, err := c.CreateIndexEndpoint(ctx, req)
    82  	if err != nil {
    83  		// TODO: Handle error.
    84  	}
    85  
    86  	resp, err := op.Wait(ctx)
    87  	if err != nil {
    88  		// TODO: Handle error.
    89  	}
    90  	// TODO: Use resp.
    91  	_ = resp
    92  }
    93  
    94  func ExampleIndexEndpointClient_DeleteIndexEndpoint() {
    95  	ctx := context.Background()
    96  	// This snippet has been automatically generated and should be regarded as a code template only.
    97  	// It will require modifications to work:
    98  	// - It may require correct/in-range values for request initialization.
    99  	// - It may require specifying regional endpoints when creating the service client as shown in:
   100  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   101  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &aiplatformpb.DeleteIndexEndpointRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeleteIndexEndpointRequest.
   110  	}
   111  	op, err := c.DeleteIndexEndpoint(ctx, req)
   112  	if err != nil {
   113  		// TODO: Handle error.
   114  	}
   115  
   116  	err = op.Wait(ctx)
   117  	if err != nil {
   118  		// TODO: Handle error.
   119  	}
   120  }
   121  
   122  func ExampleIndexEndpointClient_DeployIndex() {
   123  	ctx := context.Background()
   124  	// This snippet has been automatically generated and should be regarded as a code template only.
   125  	// It will require modifications to work:
   126  	// - It may require correct/in-range values for request initialization.
   127  	// - It may require specifying regional endpoints when creating the service client as shown in:
   128  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   129  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   130  	if err != nil {
   131  		// TODO: Handle error.
   132  	}
   133  	defer c.Close()
   134  
   135  	req := &aiplatformpb.DeployIndexRequest{
   136  		// TODO: Fill request struct fields.
   137  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeployIndexRequest.
   138  	}
   139  	op, err := c.DeployIndex(ctx, req)
   140  	if err != nil {
   141  		// TODO: Handle error.
   142  	}
   143  
   144  	resp, err := op.Wait(ctx)
   145  	if err != nil {
   146  		// TODO: Handle error.
   147  	}
   148  	// TODO: Use resp.
   149  	_ = resp
   150  }
   151  
   152  func ExampleIndexEndpointClient_GetIndexEndpoint() {
   153  	ctx := context.Background()
   154  	// This snippet has been automatically generated and should be regarded as a code template only.
   155  	// It will require modifications to work:
   156  	// - It may require correct/in-range values for request initialization.
   157  	// - It may require specifying regional endpoints when creating the service client as shown in:
   158  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   159  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   160  	if err != nil {
   161  		// TODO: Handle error.
   162  	}
   163  	defer c.Close()
   164  
   165  	req := &aiplatformpb.GetIndexEndpointRequest{
   166  		// TODO: Fill request struct fields.
   167  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetIndexEndpointRequest.
   168  	}
   169  	resp, err := c.GetIndexEndpoint(ctx, req)
   170  	if err != nil {
   171  		// TODO: Handle error.
   172  	}
   173  	// TODO: Use resp.
   174  	_ = resp
   175  }
   176  
   177  func ExampleIndexEndpointClient_ListIndexEndpoints() {
   178  	ctx := context.Background()
   179  	// This snippet has been automatically generated and should be regarded as a code template only.
   180  	// It will require modifications to work:
   181  	// - It may require correct/in-range values for request initialization.
   182  	// - It may require specifying regional endpoints when creating the service client as shown in:
   183  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   184  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   185  	if err != nil {
   186  		// TODO: Handle error.
   187  	}
   188  	defer c.Close()
   189  
   190  	req := &aiplatformpb.ListIndexEndpointsRequest{
   191  		// TODO: Fill request struct fields.
   192  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListIndexEndpointsRequest.
   193  	}
   194  	it := c.ListIndexEndpoints(ctx, req)
   195  	for {
   196  		resp, err := it.Next()
   197  		if err == iterator.Done {
   198  			break
   199  		}
   200  		if err != nil {
   201  			// TODO: Handle error.
   202  		}
   203  		// TODO: Use resp.
   204  		_ = resp
   205  
   206  		// If you need to access the underlying RPC response,
   207  		// you can do so by casting the `Response` as below.
   208  		// Otherwise, remove this line. Only populated after
   209  		// first call to Next(). Not safe for concurrent access.
   210  		_ = it.Response.(*aiplatformpb.ListIndexEndpointsResponse)
   211  	}
   212  }
   213  
   214  func ExampleIndexEndpointClient_MutateDeployedIndex() {
   215  	ctx := context.Background()
   216  	// This snippet has been automatically generated and should be regarded as a code template only.
   217  	// It will require modifications to work:
   218  	// - It may require correct/in-range values for request initialization.
   219  	// - It may require specifying regional endpoints when creating the service client as shown in:
   220  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   221  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   222  	if err != nil {
   223  		// TODO: Handle error.
   224  	}
   225  	defer c.Close()
   226  
   227  	req := &aiplatformpb.MutateDeployedIndexRequest{
   228  		// TODO: Fill request struct fields.
   229  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#MutateDeployedIndexRequest.
   230  	}
   231  	op, err := c.MutateDeployedIndex(ctx, req)
   232  	if err != nil {
   233  		// TODO: Handle error.
   234  	}
   235  
   236  	resp, err := op.Wait(ctx)
   237  	if err != nil {
   238  		// TODO: Handle error.
   239  	}
   240  	// TODO: Use resp.
   241  	_ = resp
   242  }
   243  
   244  func ExampleIndexEndpointClient_UndeployIndex() {
   245  	ctx := context.Background()
   246  	// This snippet has been automatically generated and should be regarded as a code template only.
   247  	// It will require modifications to work:
   248  	// - It may require correct/in-range values for request initialization.
   249  	// - It may require specifying regional endpoints when creating the service client as shown in:
   250  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   251  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   252  	if err != nil {
   253  		// TODO: Handle error.
   254  	}
   255  	defer c.Close()
   256  
   257  	req := &aiplatformpb.UndeployIndexRequest{
   258  		// TODO: Fill request struct fields.
   259  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UndeployIndexRequest.
   260  	}
   261  	op, err := c.UndeployIndex(ctx, req)
   262  	if err != nil {
   263  		// TODO: Handle error.
   264  	}
   265  
   266  	resp, err := op.Wait(ctx)
   267  	if err != nil {
   268  		// TODO: Handle error.
   269  	}
   270  	// TODO: Use resp.
   271  	_ = resp
   272  }
   273  
   274  func ExampleIndexEndpointClient_UpdateIndexEndpoint() {
   275  	ctx := context.Background()
   276  	// This snippet has been automatically generated and should be regarded as a code template only.
   277  	// It will require modifications to work:
   278  	// - It may require correct/in-range values for request initialization.
   279  	// - It may require specifying regional endpoints when creating the service client as shown in:
   280  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   281  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   282  	if err != nil {
   283  		// TODO: Handle error.
   284  	}
   285  	defer c.Close()
   286  
   287  	req := &aiplatformpb.UpdateIndexEndpointRequest{
   288  		// TODO: Fill request struct fields.
   289  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateIndexEndpointRequest.
   290  	}
   291  	resp, err := c.UpdateIndexEndpoint(ctx, req)
   292  	if err != nil {
   293  		// TODO: Handle error.
   294  	}
   295  	// TODO: Use resp.
   296  	_ = resp
   297  }
   298  
   299  func ExampleIndexEndpointClient_GetLocation() {
   300  	ctx := context.Background()
   301  	// This snippet has been automatically generated and should be regarded as a code template only.
   302  	// It will require modifications to work:
   303  	// - It may require correct/in-range values for request initialization.
   304  	// - It may require specifying regional endpoints when creating the service client as shown in:
   305  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   306  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   307  	if err != nil {
   308  		// TODO: Handle error.
   309  	}
   310  	defer c.Close()
   311  
   312  	req := &locationpb.GetLocationRequest{
   313  		// TODO: Fill request struct fields.
   314  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   315  	}
   316  	resp, err := c.GetLocation(ctx, req)
   317  	if err != nil {
   318  		// TODO: Handle error.
   319  	}
   320  	// TODO: Use resp.
   321  	_ = resp
   322  }
   323  
   324  func ExampleIndexEndpointClient_ListLocations() {
   325  	ctx := context.Background()
   326  	// This snippet has been automatically generated and should be regarded as a code template only.
   327  	// It will require modifications to work:
   328  	// - It may require correct/in-range values for request initialization.
   329  	// - It may require specifying regional endpoints when creating the service client as shown in:
   330  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   331  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   332  	if err != nil {
   333  		// TODO: Handle error.
   334  	}
   335  	defer c.Close()
   336  
   337  	req := &locationpb.ListLocationsRequest{
   338  		// TODO: Fill request struct fields.
   339  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   340  	}
   341  	it := c.ListLocations(ctx, req)
   342  	for {
   343  		resp, err := it.Next()
   344  		if err == iterator.Done {
   345  			break
   346  		}
   347  		if err != nil {
   348  			// TODO: Handle error.
   349  		}
   350  		// TODO: Use resp.
   351  		_ = resp
   352  
   353  		// If you need to access the underlying RPC response,
   354  		// you can do so by casting the `Response` as below.
   355  		// Otherwise, remove this line. Only populated after
   356  		// first call to Next(). Not safe for concurrent access.
   357  		_ = it.Response.(*locationpb.ListLocationsResponse)
   358  	}
   359  }
   360  
   361  func ExampleIndexEndpointClient_GetIamPolicy() {
   362  	ctx := context.Background()
   363  	// This snippet has been automatically generated and should be regarded as a code template only.
   364  	// It will require modifications to work:
   365  	// - It may require correct/in-range values for request initialization.
   366  	// - It may require specifying regional endpoints when creating the service client as shown in:
   367  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   368  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   369  	if err != nil {
   370  		// TODO: Handle error.
   371  	}
   372  	defer c.Close()
   373  
   374  	req := &iampb.GetIamPolicyRequest{
   375  		// TODO: Fill request struct fields.
   376  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   377  	}
   378  	resp, err := c.GetIamPolicy(ctx, req)
   379  	if err != nil {
   380  		// TODO: Handle error.
   381  	}
   382  	// TODO: Use resp.
   383  	_ = resp
   384  }
   385  
   386  func ExampleIndexEndpointClient_SetIamPolicy() {
   387  	ctx := context.Background()
   388  	// This snippet has been automatically generated and should be regarded as a code template only.
   389  	// It will require modifications to work:
   390  	// - It may require correct/in-range values for request initialization.
   391  	// - It may require specifying regional endpoints when creating the service client as shown in:
   392  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   393  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   394  	if err != nil {
   395  		// TODO: Handle error.
   396  	}
   397  	defer c.Close()
   398  
   399  	req := &iampb.SetIamPolicyRequest{
   400  		// TODO: Fill request struct fields.
   401  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   402  	}
   403  	resp, err := c.SetIamPolicy(ctx, req)
   404  	if err != nil {
   405  		// TODO: Handle error.
   406  	}
   407  	// TODO: Use resp.
   408  	_ = resp
   409  }
   410  
   411  func ExampleIndexEndpointClient_TestIamPermissions() {
   412  	ctx := context.Background()
   413  	// This snippet has been automatically generated and should be regarded as a code template only.
   414  	// It will require modifications to work:
   415  	// - It may require correct/in-range values for request initialization.
   416  	// - It may require specifying regional endpoints when creating the service client as shown in:
   417  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   418  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   419  	if err != nil {
   420  		// TODO: Handle error.
   421  	}
   422  	defer c.Close()
   423  
   424  	req := &iampb.TestIamPermissionsRequest{
   425  		// TODO: Fill request struct fields.
   426  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   427  	}
   428  	resp, err := c.TestIamPermissions(ctx, req)
   429  	if err != nil {
   430  		// TODO: Handle error.
   431  	}
   432  	// TODO: Use resp.
   433  	_ = resp
   434  }
   435  
   436  func ExampleIndexEndpointClient_CancelOperation() {
   437  	ctx := context.Background()
   438  	// This snippet has been automatically generated and should be regarded as a code template only.
   439  	// It will require modifications to work:
   440  	// - It may require correct/in-range values for request initialization.
   441  	// - It may require specifying regional endpoints when creating the service client as shown in:
   442  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   443  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   444  	if err != nil {
   445  		// TODO: Handle error.
   446  	}
   447  	defer c.Close()
   448  
   449  	req := &longrunningpb.CancelOperationRequest{
   450  		// TODO: Fill request struct fields.
   451  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   452  	}
   453  	err = c.CancelOperation(ctx, req)
   454  	if err != nil {
   455  		// TODO: Handle error.
   456  	}
   457  }
   458  
   459  func ExampleIndexEndpointClient_DeleteOperation() {
   460  	ctx := context.Background()
   461  	// This snippet has been automatically generated and should be regarded as a code template only.
   462  	// It will require modifications to work:
   463  	// - It may require correct/in-range values for request initialization.
   464  	// - It may require specifying regional endpoints when creating the service client as shown in:
   465  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   466  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   467  	if err != nil {
   468  		// TODO: Handle error.
   469  	}
   470  	defer c.Close()
   471  
   472  	req := &longrunningpb.DeleteOperationRequest{
   473  		// TODO: Fill request struct fields.
   474  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   475  	}
   476  	err = c.DeleteOperation(ctx, req)
   477  	if err != nil {
   478  		// TODO: Handle error.
   479  	}
   480  }
   481  
   482  func ExampleIndexEndpointClient_GetOperation() {
   483  	ctx := context.Background()
   484  	// This snippet has been automatically generated and should be regarded as a code template only.
   485  	// It will require modifications to work:
   486  	// - It may require correct/in-range values for request initialization.
   487  	// - It may require specifying regional endpoints when creating the service client as shown in:
   488  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   489  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   490  	if err != nil {
   491  		// TODO: Handle error.
   492  	}
   493  	defer c.Close()
   494  
   495  	req := &longrunningpb.GetOperationRequest{
   496  		// TODO: Fill request struct fields.
   497  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   498  	}
   499  	resp, err := c.GetOperation(ctx, req)
   500  	if err != nil {
   501  		// TODO: Handle error.
   502  	}
   503  	// TODO: Use resp.
   504  	_ = resp
   505  }
   506  
   507  func ExampleIndexEndpointClient_ListOperations() {
   508  	ctx := context.Background()
   509  	// This snippet has been automatically generated and should be regarded as a code template only.
   510  	// It will require modifications to work:
   511  	// - It may require correct/in-range values for request initialization.
   512  	// - It may require specifying regional endpoints when creating the service client as shown in:
   513  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   514  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   515  	if err != nil {
   516  		// TODO: Handle error.
   517  	}
   518  	defer c.Close()
   519  
   520  	req := &longrunningpb.ListOperationsRequest{
   521  		// TODO: Fill request struct fields.
   522  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   523  	}
   524  	it := c.ListOperations(ctx, req)
   525  	for {
   526  		resp, err := it.Next()
   527  		if err == iterator.Done {
   528  			break
   529  		}
   530  		if err != nil {
   531  			// TODO: Handle error.
   532  		}
   533  		// TODO: Use resp.
   534  		_ = resp
   535  
   536  		// If you need to access the underlying RPC response,
   537  		// you can do so by casting the `Response` as below.
   538  		// Otherwise, remove this line. Only populated after
   539  		// first call to Next(). Not safe for concurrent access.
   540  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   541  	}
   542  }
   543  
   544  func ExampleIndexEndpointClient_WaitOperation() {
   545  	ctx := context.Background()
   546  	// This snippet has been automatically generated and should be regarded as a code template only.
   547  	// It will require modifications to work:
   548  	// - It may require correct/in-range values for request initialization.
   549  	// - It may require specifying regional endpoints when creating the service client as shown in:
   550  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   551  	c, err := aiplatform.NewIndexEndpointClient(ctx)
   552  	if err != nil {
   553  		// TODO: Handle error.
   554  	}
   555  	defer c.Close()
   556  
   557  	req := &longrunningpb.WaitOperationRequest{
   558  		// TODO: Fill request struct fields.
   559  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   560  	}
   561  	resp, err := c.WaitOperation(ctx, req)
   562  	if err != nil {
   563  		// TODO: Handle error.
   564  	}
   565  	// TODO: Use resp.
   566  	_ = resp
   567  }