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