...

Source file src/cloud.google.com/go/storage/control/apiv2/storage_control_client_example_test.go

Documentation: cloud.google.com/go/storage/control/apiv2

     1  // Copyright 2024 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 control_test
    18  
    19  import (
    20  	"context"
    21  
    22  	control "cloud.google.com/go/storage/control/apiv2"
    23  	controlpb "cloud.google.com/go/storage/control/apiv2/controlpb"
    24  	"google.golang.org/api/iterator"
    25  )
    26  
    27  func ExampleNewStorageControlClient() {
    28  	ctx := context.Background()
    29  	// This snippet has been automatically generated and should be regarded as a code template only.
    30  	// It will require modifications to work:
    31  	// - It may require correct/in-range values for request initialization.
    32  	// - It may require specifying regional endpoints when creating the service client as shown in:
    33  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    34  	c, err := control.NewStorageControlClient(ctx)
    35  	if err != nil {
    36  		// TODO: Handle error.
    37  	}
    38  	defer c.Close()
    39  
    40  	// TODO: Use client.
    41  	_ = c
    42  }
    43  
    44  func ExampleStorageControlClient_CreateFolder() {
    45  	ctx := context.Background()
    46  	// This snippet has been automatically generated and should be regarded as a code template only.
    47  	// It will require modifications to work:
    48  	// - It may require correct/in-range values for request initialization.
    49  	// - It may require specifying regional endpoints when creating the service client as shown in:
    50  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    51  	c, err := control.NewStorageControlClient(ctx)
    52  	if err != nil {
    53  		// TODO: Handle error.
    54  	}
    55  	defer c.Close()
    56  
    57  	req := &controlpb.CreateFolderRequest{
    58  		// TODO: Fill request struct fields.
    59  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#CreateFolderRequest.
    60  	}
    61  	resp, err := c.CreateFolder(ctx, req)
    62  	if err != nil {
    63  		// TODO: Handle error.
    64  	}
    65  	// TODO: Use resp.
    66  	_ = resp
    67  }
    68  
    69  func ExampleStorageControlClient_CreateManagedFolder() {
    70  	ctx := context.Background()
    71  	// This snippet has been automatically generated and should be regarded as a code template only.
    72  	// It will require modifications to work:
    73  	// - It may require correct/in-range values for request initialization.
    74  	// - It may require specifying regional endpoints when creating the service client as shown in:
    75  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    76  	c, err := control.NewStorageControlClient(ctx)
    77  	if err != nil {
    78  		// TODO: Handle error.
    79  	}
    80  	defer c.Close()
    81  
    82  	req := &controlpb.CreateManagedFolderRequest{
    83  		// TODO: Fill request struct fields.
    84  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#CreateManagedFolderRequest.
    85  	}
    86  	resp, err := c.CreateManagedFolder(ctx, req)
    87  	if err != nil {
    88  		// TODO: Handle error.
    89  	}
    90  	// TODO: Use resp.
    91  	_ = resp
    92  }
    93  
    94  func ExampleStorageControlClient_DeleteFolder() {
    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 := control.NewStorageControlClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &controlpb.DeleteFolderRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#DeleteFolderRequest.
   110  	}
   111  	err = c.DeleteFolder(ctx, req)
   112  	if err != nil {
   113  		// TODO: Handle error.
   114  	}
   115  }
   116  
   117  func ExampleStorageControlClient_DeleteManagedFolder() {
   118  	ctx := context.Background()
   119  	// This snippet has been automatically generated and should be regarded as a code template only.
   120  	// It will require modifications to work:
   121  	// - It may require correct/in-range values for request initialization.
   122  	// - It may require specifying regional endpoints when creating the service client as shown in:
   123  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   124  	c, err := control.NewStorageControlClient(ctx)
   125  	if err != nil {
   126  		// TODO: Handle error.
   127  	}
   128  	defer c.Close()
   129  
   130  	req := &controlpb.DeleteManagedFolderRequest{
   131  		// TODO: Fill request struct fields.
   132  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#DeleteManagedFolderRequest.
   133  	}
   134  	err = c.DeleteManagedFolder(ctx, req)
   135  	if err != nil {
   136  		// TODO: Handle error.
   137  	}
   138  }
   139  
   140  func ExampleStorageControlClient_GetFolder() {
   141  	ctx := context.Background()
   142  	// This snippet has been automatically generated and should be regarded as a code template only.
   143  	// It will require modifications to work:
   144  	// - It may require correct/in-range values for request initialization.
   145  	// - It may require specifying regional endpoints when creating the service client as shown in:
   146  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   147  	c, err := control.NewStorageControlClient(ctx)
   148  	if err != nil {
   149  		// TODO: Handle error.
   150  	}
   151  	defer c.Close()
   152  
   153  	req := &controlpb.GetFolderRequest{
   154  		// TODO: Fill request struct fields.
   155  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#GetFolderRequest.
   156  	}
   157  	resp, err := c.GetFolder(ctx, req)
   158  	if err != nil {
   159  		// TODO: Handle error.
   160  	}
   161  	// TODO: Use resp.
   162  	_ = resp
   163  }
   164  
   165  func ExampleStorageControlClient_GetManagedFolder() {
   166  	ctx := context.Background()
   167  	// This snippet has been automatically generated and should be regarded as a code template only.
   168  	// It will require modifications to work:
   169  	// - It may require correct/in-range values for request initialization.
   170  	// - It may require specifying regional endpoints when creating the service client as shown in:
   171  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   172  	c, err := control.NewStorageControlClient(ctx)
   173  	if err != nil {
   174  		// TODO: Handle error.
   175  	}
   176  	defer c.Close()
   177  
   178  	req := &controlpb.GetManagedFolderRequest{
   179  		// TODO: Fill request struct fields.
   180  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#GetManagedFolderRequest.
   181  	}
   182  	resp, err := c.GetManagedFolder(ctx, req)
   183  	if err != nil {
   184  		// TODO: Handle error.
   185  	}
   186  	// TODO: Use resp.
   187  	_ = resp
   188  }
   189  
   190  func ExampleStorageControlClient_GetStorageLayout() {
   191  	ctx := context.Background()
   192  	// This snippet has been automatically generated and should be regarded as a code template only.
   193  	// It will require modifications to work:
   194  	// - It may require correct/in-range values for request initialization.
   195  	// - It may require specifying regional endpoints when creating the service client as shown in:
   196  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   197  	c, err := control.NewStorageControlClient(ctx)
   198  	if err != nil {
   199  		// TODO: Handle error.
   200  	}
   201  	defer c.Close()
   202  
   203  	req := &controlpb.GetStorageLayoutRequest{
   204  		// TODO: Fill request struct fields.
   205  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#GetStorageLayoutRequest.
   206  	}
   207  	resp, err := c.GetStorageLayout(ctx, req)
   208  	if err != nil {
   209  		// TODO: Handle error.
   210  	}
   211  	// TODO: Use resp.
   212  	_ = resp
   213  }
   214  
   215  func ExampleStorageControlClient_ListFolders() {
   216  	ctx := context.Background()
   217  	// This snippet has been automatically generated and should be regarded as a code template only.
   218  	// It will require modifications to work:
   219  	// - It may require correct/in-range values for request initialization.
   220  	// - It may require specifying regional endpoints when creating the service client as shown in:
   221  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   222  	c, err := control.NewStorageControlClient(ctx)
   223  	if err != nil {
   224  		// TODO: Handle error.
   225  	}
   226  	defer c.Close()
   227  
   228  	req := &controlpb.ListFoldersRequest{
   229  		// TODO: Fill request struct fields.
   230  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#ListFoldersRequest.
   231  	}
   232  	it := c.ListFolders(ctx, req)
   233  	for {
   234  		resp, err := it.Next()
   235  		if err == iterator.Done {
   236  			break
   237  		}
   238  		if err != nil {
   239  			// TODO: Handle error.
   240  		}
   241  		// TODO: Use resp.
   242  		_ = resp
   243  
   244  		// If you need to access the underlying RPC response,
   245  		// you can do so by casting the `Response` as below.
   246  		// Otherwise, remove this line. Only populated after
   247  		// first call to Next(). Not safe for concurrent access.
   248  		_ = it.Response.(*controlpb.ListFoldersResponse)
   249  	}
   250  }
   251  
   252  func ExampleStorageControlClient_ListManagedFolders() {
   253  	ctx := context.Background()
   254  	// This snippet has been automatically generated and should be regarded as a code template only.
   255  	// It will require modifications to work:
   256  	// - It may require correct/in-range values for request initialization.
   257  	// - It may require specifying regional endpoints when creating the service client as shown in:
   258  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   259  	c, err := control.NewStorageControlClient(ctx)
   260  	if err != nil {
   261  		// TODO: Handle error.
   262  	}
   263  	defer c.Close()
   264  
   265  	req := &controlpb.ListManagedFoldersRequest{
   266  		// TODO: Fill request struct fields.
   267  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#ListManagedFoldersRequest.
   268  	}
   269  	it := c.ListManagedFolders(ctx, req)
   270  	for {
   271  		resp, err := it.Next()
   272  		if err == iterator.Done {
   273  			break
   274  		}
   275  		if err != nil {
   276  			// TODO: Handle error.
   277  		}
   278  		// TODO: Use resp.
   279  		_ = resp
   280  
   281  		// If you need to access the underlying RPC response,
   282  		// you can do so by casting the `Response` as below.
   283  		// Otherwise, remove this line. Only populated after
   284  		// first call to Next(). Not safe for concurrent access.
   285  		_ = it.Response.(*controlpb.ListManagedFoldersResponse)
   286  	}
   287  }
   288  
   289  func ExampleStorageControlClient_RenameFolder() {
   290  	ctx := context.Background()
   291  	// This snippet has been automatically generated and should be regarded as a code template only.
   292  	// It will require modifications to work:
   293  	// - It may require correct/in-range values for request initialization.
   294  	// - It may require specifying regional endpoints when creating the service client as shown in:
   295  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   296  	c, err := control.NewStorageControlClient(ctx)
   297  	if err != nil {
   298  		// TODO: Handle error.
   299  	}
   300  	defer c.Close()
   301  
   302  	req := &controlpb.RenameFolderRequest{
   303  		// TODO: Fill request struct fields.
   304  		// See https://pkg.go.dev/cloud.google.com/go/storage/control/apiv2/controlpb#RenameFolderRequest.
   305  	}
   306  	op, err := c.RenameFolder(ctx, req)
   307  	if err != nil {
   308  		// TODO: Handle error.
   309  	}
   310  
   311  	resp, err := op.Wait(ctx)
   312  	if err != nil {
   313  		// TODO: Handle error.
   314  	}
   315  	// TODO: Use resp.
   316  	_ = resp
   317  }
   318  

View as plain text