cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/index_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 ExampleNewIndexClient() {
    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.NewIndexClient(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 ExampleNewIndexRESTClient() {
    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.NewIndexRESTClient(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 ExampleIndexClient_CreateIndex() {
    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.NewIndexClient(ctx)
    72  	if err != nil {
    73  		// TODO: Handle error.
    74  	}
    75  	defer c.Close()
    76  
    77  	req := &aiplatformpb.CreateIndexRequest{
    78  		// TODO: Fill request struct fields.
    79  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateIndexRequest.
    80  	}
    81  	op, err := c.CreateIndex(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 ExampleIndexClient_DeleteIndex() {
    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.NewIndexClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &aiplatformpb.DeleteIndexRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeleteIndexRequest.
   110  	}
   111  	op, err := c.DeleteIndex(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 ExampleIndexClient_GetIndex() {
   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.NewIndexClient(ctx)
   130  	if err != nil {
   131  		// TODO: Handle error.
   132  	}
   133  	defer c.Close()
   134  
   135  	req := &aiplatformpb.GetIndexRequest{
   136  		// TODO: Fill request struct fields.
   137  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetIndexRequest.
   138  	}
   139  	resp, err := c.GetIndex(ctx, req)
   140  	if err != nil {
   141  		// TODO: Handle error.
   142  	}
   143  	// TODO: Use resp.
   144  	_ = resp
   145  }
   146  
   147  func ExampleIndexClient_ImportIndex() {
   148  	ctx := context.Background()
   149  	// This snippet has been automatically generated and should be regarded as a code template only.
   150  	// It will require modifications to work:
   151  	// - It may require correct/in-range values for request initialization.
   152  	// - It may require specifying regional endpoints when creating the service client as shown in:
   153  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   154  	c, err := aiplatform.NewIndexClient(ctx)
   155  	if err != nil {
   156  		// TODO: Handle error.
   157  	}
   158  	defer c.Close()
   159  
   160  	req := &aiplatformpb.ImportIndexRequest{
   161  		// TODO: Fill request struct fields.
   162  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ImportIndexRequest.
   163  	}
   164  	op, err := c.ImportIndex(ctx, req)
   165  	if err != nil {
   166  		// TODO: Handle error.
   167  	}
   168  
   169  	resp, err := op.Wait(ctx)
   170  	if err != nil {
   171  		// TODO: Handle error.
   172  	}
   173  	// TODO: Use resp.
   174  	_ = resp
   175  }
   176  
   177  func ExampleIndexClient_ListIndexes() {
   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.NewIndexClient(ctx)
   185  	if err != nil {
   186  		// TODO: Handle error.
   187  	}
   188  	defer c.Close()
   189  
   190  	req := &aiplatformpb.ListIndexesRequest{
   191  		// TODO: Fill request struct fields.
   192  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListIndexesRequest.
   193  	}
   194  	it := c.ListIndexes(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.ListIndexesResponse)
   211  	}
   212  }
   213  
   214  func ExampleIndexClient_RemoveDatapoints() {
   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.NewIndexClient(ctx)
   222  	if err != nil {
   223  		// TODO: Handle error.
   224  	}
   225  	defer c.Close()
   226  
   227  	req := &aiplatformpb.RemoveDatapointsRequest{
   228  		// TODO: Fill request struct fields.
   229  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#RemoveDatapointsRequest.
   230  	}
   231  	resp, err := c.RemoveDatapoints(ctx, req)
   232  	if err != nil {
   233  		// TODO: Handle error.
   234  	}
   235  	// TODO: Use resp.
   236  	_ = resp
   237  }
   238  
   239  func ExampleIndexClient_UpdateIndex() {
   240  	ctx := context.Background()
   241  	// This snippet has been automatically generated and should be regarded as a code template only.
   242  	// It will require modifications to work:
   243  	// - It may require correct/in-range values for request initialization.
   244  	// - It may require specifying regional endpoints when creating the service client as shown in:
   245  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   246  	c, err := aiplatform.NewIndexClient(ctx)
   247  	if err != nil {
   248  		// TODO: Handle error.
   249  	}
   250  	defer c.Close()
   251  
   252  	req := &aiplatformpb.UpdateIndexRequest{
   253  		// TODO: Fill request struct fields.
   254  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateIndexRequest.
   255  	}
   256  	op, err := c.UpdateIndex(ctx, req)
   257  	if err != nil {
   258  		// TODO: Handle error.
   259  	}
   260  
   261  	resp, err := op.Wait(ctx)
   262  	if err != nil {
   263  		// TODO: Handle error.
   264  	}
   265  	// TODO: Use resp.
   266  	_ = resp
   267  }
   268  
   269  func ExampleIndexClient_UpsertDatapoints() {
   270  	ctx := context.Background()
   271  	// This snippet has been automatically generated and should be regarded as a code template only.
   272  	// It will require modifications to work:
   273  	// - It may require correct/in-range values for request initialization.
   274  	// - It may require specifying regional endpoints when creating the service client as shown in:
   275  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   276  	c, err := aiplatform.NewIndexClient(ctx)
   277  	if err != nil {
   278  		// TODO: Handle error.
   279  	}
   280  	defer c.Close()
   281  
   282  	req := &aiplatformpb.UpsertDatapointsRequest{
   283  		// TODO: Fill request struct fields.
   284  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpsertDatapointsRequest.
   285  	}
   286  	resp, err := c.UpsertDatapoints(ctx, req)
   287  	if err != nil {
   288  		// TODO: Handle error.
   289  	}
   290  	// TODO: Use resp.
   291  	_ = resp
   292  }
   293  
   294  func ExampleIndexClient_GetLocation() {
   295  	ctx := context.Background()
   296  	// This snippet has been automatically generated and should be regarded as a code template only.
   297  	// It will require modifications to work:
   298  	// - It may require correct/in-range values for request initialization.
   299  	// - It may require specifying regional endpoints when creating the service client as shown in:
   300  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   301  	c, err := aiplatform.NewIndexClient(ctx)
   302  	if err != nil {
   303  		// TODO: Handle error.
   304  	}
   305  	defer c.Close()
   306  
   307  	req := &locationpb.GetLocationRequest{
   308  		// TODO: Fill request struct fields.
   309  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   310  	}
   311  	resp, err := c.GetLocation(ctx, req)
   312  	if err != nil {
   313  		// TODO: Handle error.
   314  	}
   315  	// TODO: Use resp.
   316  	_ = resp
   317  }
   318  
   319  func ExampleIndexClient_ListLocations() {
   320  	ctx := context.Background()
   321  	// This snippet has been automatically generated and should be regarded as a code template only.
   322  	// It will require modifications to work:
   323  	// - It may require correct/in-range values for request initialization.
   324  	// - It may require specifying regional endpoints when creating the service client as shown in:
   325  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   326  	c, err := aiplatform.NewIndexClient(ctx)
   327  	if err != nil {
   328  		// TODO: Handle error.
   329  	}
   330  	defer c.Close()
   331  
   332  	req := &locationpb.ListLocationsRequest{
   333  		// TODO: Fill request struct fields.
   334  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   335  	}
   336  	it := c.ListLocations(ctx, req)
   337  	for {
   338  		resp, err := it.Next()
   339  		if err == iterator.Done {
   340  			break
   341  		}
   342  		if err != nil {
   343  			// TODO: Handle error.
   344  		}
   345  		// TODO: Use resp.
   346  		_ = resp
   347  
   348  		// If you need to access the underlying RPC response,
   349  		// you can do so by casting the `Response` as below.
   350  		// Otherwise, remove this line. Only populated after
   351  		// first call to Next(). Not safe for concurrent access.
   352  		_ = it.Response.(*locationpb.ListLocationsResponse)
   353  	}
   354  }
   355  
   356  func ExampleIndexClient_GetIamPolicy() {
   357  	ctx := context.Background()
   358  	// This snippet has been automatically generated and should be regarded as a code template only.
   359  	// It will require modifications to work:
   360  	// - It may require correct/in-range values for request initialization.
   361  	// - It may require specifying regional endpoints when creating the service client as shown in:
   362  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   363  	c, err := aiplatform.NewIndexClient(ctx)
   364  	if err != nil {
   365  		// TODO: Handle error.
   366  	}
   367  	defer c.Close()
   368  
   369  	req := &iampb.GetIamPolicyRequest{
   370  		// TODO: Fill request struct fields.
   371  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   372  	}
   373  	resp, err := c.GetIamPolicy(ctx, req)
   374  	if err != nil {
   375  		// TODO: Handle error.
   376  	}
   377  	// TODO: Use resp.
   378  	_ = resp
   379  }
   380  
   381  func ExampleIndexClient_SetIamPolicy() {
   382  	ctx := context.Background()
   383  	// This snippet has been automatically generated and should be regarded as a code template only.
   384  	// It will require modifications to work:
   385  	// - It may require correct/in-range values for request initialization.
   386  	// - It may require specifying regional endpoints when creating the service client as shown in:
   387  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   388  	c, err := aiplatform.NewIndexClient(ctx)
   389  	if err != nil {
   390  		// TODO: Handle error.
   391  	}
   392  	defer c.Close()
   393  
   394  	req := &iampb.SetIamPolicyRequest{
   395  		// TODO: Fill request struct fields.
   396  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   397  	}
   398  	resp, err := c.SetIamPolicy(ctx, req)
   399  	if err != nil {
   400  		// TODO: Handle error.
   401  	}
   402  	// TODO: Use resp.
   403  	_ = resp
   404  }
   405  
   406  func ExampleIndexClient_TestIamPermissions() {
   407  	ctx := context.Background()
   408  	// This snippet has been automatically generated and should be regarded as a code template only.
   409  	// It will require modifications to work:
   410  	// - It may require correct/in-range values for request initialization.
   411  	// - It may require specifying regional endpoints when creating the service client as shown in:
   412  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   413  	c, err := aiplatform.NewIndexClient(ctx)
   414  	if err != nil {
   415  		// TODO: Handle error.
   416  	}
   417  	defer c.Close()
   418  
   419  	req := &iampb.TestIamPermissionsRequest{
   420  		// TODO: Fill request struct fields.
   421  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   422  	}
   423  	resp, err := c.TestIamPermissions(ctx, req)
   424  	if err != nil {
   425  		// TODO: Handle error.
   426  	}
   427  	// TODO: Use resp.
   428  	_ = resp
   429  }
   430  
   431  func ExampleIndexClient_CancelOperation() {
   432  	ctx := context.Background()
   433  	// This snippet has been automatically generated and should be regarded as a code template only.
   434  	// It will require modifications to work:
   435  	// - It may require correct/in-range values for request initialization.
   436  	// - It may require specifying regional endpoints when creating the service client as shown in:
   437  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   438  	c, err := aiplatform.NewIndexClient(ctx)
   439  	if err != nil {
   440  		// TODO: Handle error.
   441  	}
   442  	defer c.Close()
   443  
   444  	req := &longrunningpb.CancelOperationRequest{
   445  		// TODO: Fill request struct fields.
   446  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   447  	}
   448  	err = c.CancelOperation(ctx, req)
   449  	if err != nil {
   450  		// TODO: Handle error.
   451  	}
   452  }
   453  
   454  func ExampleIndexClient_DeleteOperation() {
   455  	ctx := context.Background()
   456  	// This snippet has been automatically generated and should be regarded as a code template only.
   457  	// It will require modifications to work:
   458  	// - It may require correct/in-range values for request initialization.
   459  	// - It may require specifying regional endpoints when creating the service client as shown in:
   460  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   461  	c, err := aiplatform.NewIndexClient(ctx)
   462  	if err != nil {
   463  		// TODO: Handle error.
   464  	}
   465  	defer c.Close()
   466  
   467  	req := &longrunningpb.DeleteOperationRequest{
   468  		// TODO: Fill request struct fields.
   469  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   470  	}
   471  	err = c.DeleteOperation(ctx, req)
   472  	if err != nil {
   473  		// TODO: Handle error.
   474  	}
   475  }
   476  
   477  func ExampleIndexClient_GetOperation() {
   478  	ctx := context.Background()
   479  	// This snippet has been automatically generated and should be regarded as a code template only.
   480  	// It will require modifications to work:
   481  	// - It may require correct/in-range values for request initialization.
   482  	// - It may require specifying regional endpoints when creating the service client as shown in:
   483  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   484  	c, err := aiplatform.NewIndexClient(ctx)
   485  	if err != nil {
   486  		// TODO: Handle error.
   487  	}
   488  	defer c.Close()
   489  
   490  	req := &longrunningpb.GetOperationRequest{
   491  		// TODO: Fill request struct fields.
   492  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   493  	}
   494  	resp, err := c.GetOperation(ctx, req)
   495  	if err != nil {
   496  		// TODO: Handle error.
   497  	}
   498  	// TODO: Use resp.
   499  	_ = resp
   500  }
   501  
   502  func ExampleIndexClient_ListOperations() {
   503  	ctx := context.Background()
   504  	// This snippet has been automatically generated and should be regarded as a code template only.
   505  	// It will require modifications to work:
   506  	// - It may require correct/in-range values for request initialization.
   507  	// - It may require specifying regional endpoints when creating the service client as shown in:
   508  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   509  	c, err := aiplatform.NewIndexClient(ctx)
   510  	if err != nil {
   511  		// TODO: Handle error.
   512  	}
   513  	defer c.Close()
   514  
   515  	req := &longrunningpb.ListOperationsRequest{
   516  		// TODO: Fill request struct fields.
   517  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   518  	}
   519  	it := c.ListOperations(ctx, req)
   520  	for {
   521  		resp, err := it.Next()
   522  		if err == iterator.Done {
   523  			break
   524  		}
   525  		if err != nil {
   526  			// TODO: Handle error.
   527  		}
   528  		// TODO: Use resp.
   529  		_ = resp
   530  
   531  		// If you need to access the underlying RPC response,
   532  		// you can do so by casting the `Response` as below.
   533  		// Otherwise, remove this line. Only populated after
   534  		// first call to Next(). Not safe for concurrent access.
   535  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   536  	}
   537  }
   538  
   539  func ExampleIndexClient_WaitOperation() {
   540  	ctx := context.Background()
   541  	// This snippet has been automatically generated and should be regarded as a code template only.
   542  	// It will require modifications to work:
   543  	// - It may require correct/in-range values for request initialization.
   544  	// - It may require specifying regional endpoints when creating the service client as shown in:
   545  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   546  	c, err := aiplatform.NewIndexClient(ctx)
   547  	if err != nil {
   548  		// TODO: Handle error.
   549  	}
   550  	defer c.Close()
   551  
   552  	req := &longrunningpb.WaitOperationRequest{
   553  		// TODO: Fill request struct fields.
   554  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   555  	}
   556  	resp, err := c.WaitOperation(ctx, req)
   557  	if err != nil {
   558  		// TODO: Handle error.
   559  	}
   560  	// TODO: Use resp.
   561  	_ = resp
   562  }