cloud.google.com/go/aiplatform@v1.106.0/apiv1/gen_ai_cache_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 ExampleNewGenAiCacheClient() {
    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.NewGenAiCacheClient(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 ExampleGenAiCacheClient_CreateCachedContent() {
    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.NewGenAiCacheClient(ctx)
    55  	if err != nil {
    56  		// TODO: Handle error.
    57  	}
    58  	defer c.Close()
    59  
    60  	req := &aiplatformpb.CreateCachedContentRequest{
    61  		// TODO: Fill request struct fields.
    62  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateCachedContentRequest.
    63  	}
    64  	resp, err := c.CreateCachedContent(ctx, req)
    65  	if err != nil {
    66  		// TODO: Handle error.
    67  	}
    68  	// TODO: Use resp.
    69  	_ = resp
    70  }
    71  
    72  func ExampleGenAiCacheClient_DeleteCachedContent() {
    73  	ctx := context.Background()
    74  	// This snippet has been automatically generated and should be regarded as a code template only.
    75  	// It will require modifications to work:
    76  	// - It may require correct/in-range values for request initialization.
    77  	// - It may require specifying regional endpoints when creating the service client as shown in:
    78  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    79  	c, err := aiplatform.NewGenAiCacheClient(ctx)
    80  	if err != nil {
    81  		// TODO: Handle error.
    82  	}
    83  	defer c.Close()
    84  
    85  	req := &aiplatformpb.DeleteCachedContentRequest{
    86  		// TODO: Fill request struct fields.
    87  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeleteCachedContentRequest.
    88  	}
    89  	err = c.DeleteCachedContent(ctx, req)
    90  	if err != nil {
    91  		// TODO: Handle error.
    92  	}
    93  }
    94  
    95  func ExampleGenAiCacheClient_GetCachedContent() {
    96  	ctx := context.Background()
    97  	// This snippet has been automatically generated and should be regarded as a code template only.
    98  	// It will require modifications to work:
    99  	// - It may require correct/in-range values for request initialization.
   100  	// - It may require specifying regional endpoints when creating the service client as shown in:
   101  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   102  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   103  	if err != nil {
   104  		// TODO: Handle error.
   105  	}
   106  	defer c.Close()
   107  
   108  	req := &aiplatformpb.GetCachedContentRequest{
   109  		// TODO: Fill request struct fields.
   110  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetCachedContentRequest.
   111  	}
   112  	resp, err := c.GetCachedContent(ctx, req)
   113  	if err != nil {
   114  		// TODO: Handle error.
   115  	}
   116  	// TODO: Use resp.
   117  	_ = resp
   118  }
   119  
   120  func ExampleGenAiCacheClient_ListCachedContents() {
   121  	ctx := context.Background()
   122  	// This snippet has been automatically generated and should be regarded as a code template only.
   123  	// It will require modifications to work:
   124  	// - It may require correct/in-range values for request initialization.
   125  	// - It may require specifying regional endpoints when creating the service client as shown in:
   126  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   127  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   128  	if err != nil {
   129  		// TODO: Handle error.
   130  	}
   131  	defer c.Close()
   132  
   133  	req := &aiplatformpb.ListCachedContentsRequest{
   134  		// TODO: Fill request struct fields.
   135  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListCachedContentsRequest.
   136  	}
   137  	it := c.ListCachedContents(ctx, req)
   138  	for {
   139  		resp, err := it.Next()
   140  		if err == iterator.Done {
   141  			break
   142  		}
   143  		if err != nil {
   144  			// TODO: Handle error.
   145  		}
   146  		// TODO: Use resp.
   147  		_ = resp
   148  
   149  		// If you need to access the underlying RPC response,
   150  		// you can do so by casting the `Response` as below.
   151  		// Otherwise, remove this line. Only populated after
   152  		// first call to Next(). Not safe for concurrent access.
   153  		_ = it.Response.(*aiplatformpb.ListCachedContentsResponse)
   154  	}
   155  }
   156  
   157  func ExampleGenAiCacheClient_UpdateCachedContent() {
   158  	ctx := context.Background()
   159  	// This snippet has been automatically generated and should be regarded as a code template only.
   160  	// It will require modifications to work:
   161  	// - It may require correct/in-range values for request initialization.
   162  	// - It may require specifying regional endpoints when creating the service client as shown in:
   163  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   164  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   165  	if err != nil {
   166  		// TODO: Handle error.
   167  	}
   168  	defer c.Close()
   169  
   170  	req := &aiplatformpb.UpdateCachedContentRequest{
   171  		// TODO: Fill request struct fields.
   172  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateCachedContentRequest.
   173  	}
   174  	resp, err := c.UpdateCachedContent(ctx, req)
   175  	if err != nil {
   176  		// TODO: Handle error.
   177  	}
   178  	// TODO: Use resp.
   179  	_ = resp
   180  }
   181  
   182  func ExampleGenAiCacheClient_GetLocation() {
   183  	ctx := context.Background()
   184  	// This snippet has been automatically generated and should be regarded as a code template only.
   185  	// It will require modifications to work:
   186  	// - It may require correct/in-range values for request initialization.
   187  	// - It may require specifying regional endpoints when creating the service client as shown in:
   188  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   189  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   190  	if err != nil {
   191  		// TODO: Handle error.
   192  	}
   193  	defer c.Close()
   194  
   195  	req := &locationpb.GetLocationRequest{
   196  		// TODO: Fill request struct fields.
   197  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   198  	}
   199  	resp, err := c.GetLocation(ctx, req)
   200  	if err != nil {
   201  		// TODO: Handle error.
   202  	}
   203  	// TODO: Use resp.
   204  	_ = resp
   205  }
   206  
   207  func ExampleGenAiCacheClient_ListLocations() {
   208  	ctx := context.Background()
   209  	// This snippet has been automatically generated and should be regarded as a code template only.
   210  	// It will require modifications to work:
   211  	// - It may require correct/in-range values for request initialization.
   212  	// - It may require specifying regional endpoints when creating the service client as shown in:
   213  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   214  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   215  	if err != nil {
   216  		// TODO: Handle error.
   217  	}
   218  	defer c.Close()
   219  
   220  	req := &locationpb.ListLocationsRequest{
   221  		// TODO: Fill request struct fields.
   222  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   223  	}
   224  	it := c.ListLocations(ctx, req)
   225  	for {
   226  		resp, err := it.Next()
   227  		if err == iterator.Done {
   228  			break
   229  		}
   230  		if err != nil {
   231  			// TODO: Handle error.
   232  		}
   233  		// TODO: Use resp.
   234  		_ = resp
   235  
   236  		// If you need to access the underlying RPC response,
   237  		// you can do so by casting the `Response` as below.
   238  		// Otherwise, remove this line. Only populated after
   239  		// first call to Next(). Not safe for concurrent access.
   240  		_ = it.Response.(*locationpb.ListLocationsResponse)
   241  	}
   242  }
   243  
   244  func ExampleGenAiCacheClient_GetIamPolicy() {
   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.NewGenAiCacheClient(ctx)
   252  	if err != nil {
   253  		// TODO: Handle error.
   254  	}
   255  	defer c.Close()
   256  
   257  	req := &iampb.GetIamPolicyRequest{
   258  		// TODO: Fill request struct fields.
   259  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   260  	}
   261  	resp, err := c.GetIamPolicy(ctx, req)
   262  	if err != nil {
   263  		// TODO: Handle error.
   264  	}
   265  	// TODO: Use resp.
   266  	_ = resp
   267  }
   268  
   269  func ExampleGenAiCacheClient_SetIamPolicy() {
   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.NewGenAiCacheClient(ctx)
   277  	if err != nil {
   278  		// TODO: Handle error.
   279  	}
   280  	defer c.Close()
   281  
   282  	req := &iampb.SetIamPolicyRequest{
   283  		// TODO: Fill request struct fields.
   284  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   285  	}
   286  	resp, err := c.SetIamPolicy(ctx, req)
   287  	if err != nil {
   288  		// TODO: Handle error.
   289  	}
   290  	// TODO: Use resp.
   291  	_ = resp
   292  }
   293  
   294  func ExampleGenAiCacheClient_TestIamPermissions() {
   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.NewGenAiCacheClient(ctx)
   302  	if err != nil {
   303  		// TODO: Handle error.
   304  	}
   305  	defer c.Close()
   306  
   307  	req := &iampb.TestIamPermissionsRequest{
   308  		// TODO: Fill request struct fields.
   309  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   310  	}
   311  	resp, err := c.TestIamPermissions(ctx, req)
   312  	if err != nil {
   313  		// TODO: Handle error.
   314  	}
   315  	// TODO: Use resp.
   316  	_ = resp
   317  }
   318  
   319  func ExampleGenAiCacheClient_CancelOperation() {
   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.NewGenAiCacheClient(ctx)
   327  	if err != nil {
   328  		// TODO: Handle error.
   329  	}
   330  	defer c.Close()
   331  
   332  	req := &longrunningpb.CancelOperationRequest{
   333  		// TODO: Fill request struct fields.
   334  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   335  	}
   336  	err = c.CancelOperation(ctx, req)
   337  	if err != nil {
   338  		// TODO: Handle error.
   339  	}
   340  }
   341  
   342  func ExampleGenAiCacheClient_DeleteOperation() {
   343  	ctx := context.Background()
   344  	// This snippet has been automatically generated and should be regarded as a code template only.
   345  	// It will require modifications to work:
   346  	// - It may require correct/in-range values for request initialization.
   347  	// - It may require specifying regional endpoints when creating the service client as shown in:
   348  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   349  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   350  	if err != nil {
   351  		// TODO: Handle error.
   352  	}
   353  	defer c.Close()
   354  
   355  	req := &longrunningpb.DeleteOperationRequest{
   356  		// TODO: Fill request struct fields.
   357  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   358  	}
   359  	err = c.DeleteOperation(ctx, req)
   360  	if err != nil {
   361  		// TODO: Handle error.
   362  	}
   363  }
   364  
   365  func ExampleGenAiCacheClient_GetOperation() {
   366  	ctx := context.Background()
   367  	// This snippet has been automatically generated and should be regarded as a code template only.
   368  	// It will require modifications to work:
   369  	// - It may require correct/in-range values for request initialization.
   370  	// - It may require specifying regional endpoints when creating the service client as shown in:
   371  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   372  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   373  	if err != nil {
   374  		// TODO: Handle error.
   375  	}
   376  	defer c.Close()
   377  
   378  	req := &longrunningpb.GetOperationRequest{
   379  		// TODO: Fill request struct fields.
   380  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   381  	}
   382  	resp, err := c.GetOperation(ctx, req)
   383  	if err != nil {
   384  		// TODO: Handle error.
   385  	}
   386  	// TODO: Use resp.
   387  	_ = resp
   388  }
   389  
   390  func ExampleGenAiCacheClient_ListOperations() {
   391  	ctx := context.Background()
   392  	// This snippet has been automatically generated and should be regarded as a code template only.
   393  	// It will require modifications to work:
   394  	// - It may require correct/in-range values for request initialization.
   395  	// - It may require specifying regional endpoints when creating the service client as shown in:
   396  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   397  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   398  	if err != nil {
   399  		// TODO: Handle error.
   400  	}
   401  	defer c.Close()
   402  
   403  	req := &longrunningpb.ListOperationsRequest{
   404  		// TODO: Fill request struct fields.
   405  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   406  	}
   407  	it := c.ListOperations(ctx, req)
   408  	for {
   409  		resp, err := it.Next()
   410  		if err == iterator.Done {
   411  			break
   412  		}
   413  		if err != nil {
   414  			// TODO: Handle error.
   415  		}
   416  		// TODO: Use resp.
   417  		_ = resp
   418  
   419  		// If you need to access the underlying RPC response,
   420  		// you can do so by casting the `Response` as below.
   421  		// Otherwise, remove this line. Only populated after
   422  		// first call to Next(). Not safe for concurrent access.
   423  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   424  	}
   425  }
   426  
   427  func ExampleGenAiCacheClient_WaitOperation() {
   428  	ctx := context.Background()
   429  	// This snippet has been automatically generated and should be regarded as a code template only.
   430  	// It will require modifications to work:
   431  	// - It may require correct/in-range values for request initialization.
   432  	// - It may require specifying regional endpoints when creating the service client as shown in:
   433  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   434  	c, err := aiplatform.NewGenAiCacheClient(ctx)
   435  	if err != nil {
   436  		// TODO: Handle error.
   437  	}
   438  	defer c.Close()
   439  
   440  	req := &longrunningpb.WaitOperationRequest{
   441  		// TODO: Fill request struct fields.
   442  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   443  	}
   444  	resp, err := c.WaitOperation(ctx, req)
   445  	if err != nil {
   446  		// TODO: Handle error.
   447  	}
   448  	// TODO: Use resp.
   449  	_ = resp
   450  }