...

Source file src/cloud.google.com/go/monitoring/apiv3/v2/snooze_client_example_test.go

Documentation: cloud.google.com/go/monitoring/apiv3/v2

     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 monitoring_test
    18  
    19  import (
    20  	"context"
    21  
    22  	monitoring "cloud.google.com/go/monitoring/apiv3/v2"
    23  	monitoringpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb"
    24  	"google.golang.org/api/iterator"
    25  )
    26  
    27  func ExampleNewSnoozeClient() {
    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 := monitoring.NewSnoozeClient(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 ExampleSnoozeClient_CreateSnooze() {
    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 := monitoring.NewSnoozeClient(ctx)
    52  	if err != nil {
    53  		// TODO: Handle error.
    54  	}
    55  	defer c.Close()
    56  
    57  	req := &monitoringpb.CreateSnoozeRequest{
    58  		// TODO: Fill request struct fields.
    59  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateSnoozeRequest.
    60  	}
    61  	resp, err := c.CreateSnooze(ctx, req)
    62  	if err != nil {
    63  		// TODO: Handle error.
    64  	}
    65  	// TODO: Use resp.
    66  	_ = resp
    67  }
    68  
    69  func ExampleSnoozeClient_GetSnooze() {
    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 := monitoring.NewSnoozeClient(ctx)
    77  	if err != nil {
    78  		// TODO: Handle error.
    79  	}
    80  	defer c.Close()
    81  
    82  	req := &monitoringpb.GetSnoozeRequest{
    83  		// TODO: Fill request struct fields.
    84  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetSnoozeRequest.
    85  	}
    86  	resp, err := c.GetSnooze(ctx, req)
    87  	if err != nil {
    88  		// TODO: Handle error.
    89  	}
    90  	// TODO: Use resp.
    91  	_ = resp
    92  }
    93  
    94  func ExampleSnoozeClient_ListSnoozes() {
    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 := monitoring.NewSnoozeClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &monitoringpb.ListSnoozesRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListSnoozesRequest.
   110  	}
   111  	it := c.ListSnoozes(ctx, req)
   112  	for {
   113  		resp, err := it.Next()
   114  		if err == iterator.Done {
   115  			break
   116  		}
   117  		if err != nil {
   118  			// TODO: Handle error.
   119  		}
   120  		// TODO: Use resp.
   121  		_ = resp
   122  
   123  		// If you need to access the underlying RPC response,
   124  		// you can do so by casting the `Response` as below.
   125  		// Otherwise, remove this line. Only populated after
   126  		// first call to Next(). Not safe for concurrent access.
   127  		_ = it.Response.(*monitoringpb.ListSnoozesResponse)
   128  	}
   129  }
   130  
   131  func ExampleSnoozeClient_UpdateSnooze() {
   132  	ctx := context.Background()
   133  	// This snippet has been automatically generated and should be regarded as a code template only.
   134  	// It will require modifications to work:
   135  	// - It may require correct/in-range values for request initialization.
   136  	// - It may require specifying regional endpoints when creating the service client as shown in:
   137  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   138  	c, err := monitoring.NewSnoozeClient(ctx)
   139  	if err != nil {
   140  		// TODO: Handle error.
   141  	}
   142  	defer c.Close()
   143  
   144  	req := &monitoringpb.UpdateSnoozeRequest{
   145  		// TODO: Fill request struct fields.
   146  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#UpdateSnoozeRequest.
   147  	}
   148  	resp, err := c.UpdateSnooze(ctx, req)
   149  	if err != nil {
   150  		// TODO: Handle error.
   151  	}
   152  	// TODO: Use resp.
   153  	_ = resp
   154  }
   155  

View as plain text