...

Source file src/cloud.google.com/go/monitoring/apiv3/v2/service_monitoring_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 ExampleNewServiceMonitoringClient() {
    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.NewServiceMonitoringClient(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 ExampleServiceMonitoringClient_CreateService() {
    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.NewServiceMonitoringClient(ctx)
    52  	if err != nil {
    53  		// TODO: Handle error.
    54  	}
    55  	defer c.Close()
    56  
    57  	req := &monitoringpb.CreateServiceRequest{
    58  		// TODO: Fill request struct fields.
    59  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateServiceRequest.
    60  	}
    61  	resp, err := c.CreateService(ctx, req)
    62  	if err != nil {
    63  		// TODO: Handle error.
    64  	}
    65  	// TODO: Use resp.
    66  	_ = resp
    67  }
    68  
    69  func ExampleServiceMonitoringClient_CreateServiceLevelObjective() {
    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.NewServiceMonitoringClient(ctx)
    77  	if err != nil {
    78  		// TODO: Handle error.
    79  	}
    80  	defer c.Close()
    81  
    82  	req := &monitoringpb.CreateServiceLevelObjectiveRequest{
    83  		// TODO: Fill request struct fields.
    84  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateServiceLevelObjectiveRequest.
    85  	}
    86  	resp, err := c.CreateServiceLevelObjective(ctx, req)
    87  	if err != nil {
    88  		// TODO: Handle error.
    89  	}
    90  	// TODO: Use resp.
    91  	_ = resp
    92  }
    93  
    94  func ExampleServiceMonitoringClient_DeleteService() {
    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.NewServiceMonitoringClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &monitoringpb.DeleteServiceRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#DeleteServiceRequest.
   110  	}
   111  	err = c.DeleteService(ctx, req)
   112  	if err != nil {
   113  		// TODO: Handle error.
   114  	}
   115  }
   116  
   117  func ExampleServiceMonitoringClient_DeleteServiceLevelObjective() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   125  	if err != nil {
   126  		// TODO: Handle error.
   127  	}
   128  	defer c.Close()
   129  
   130  	req := &monitoringpb.DeleteServiceLevelObjectiveRequest{
   131  		// TODO: Fill request struct fields.
   132  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#DeleteServiceLevelObjectiveRequest.
   133  	}
   134  	err = c.DeleteServiceLevelObjective(ctx, req)
   135  	if err != nil {
   136  		// TODO: Handle error.
   137  	}
   138  }
   139  
   140  func ExampleServiceMonitoringClient_GetService() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   148  	if err != nil {
   149  		// TODO: Handle error.
   150  	}
   151  	defer c.Close()
   152  
   153  	req := &monitoringpb.GetServiceRequest{
   154  		// TODO: Fill request struct fields.
   155  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetServiceRequest.
   156  	}
   157  	resp, err := c.GetService(ctx, req)
   158  	if err != nil {
   159  		// TODO: Handle error.
   160  	}
   161  	// TODO: Use resp.
   162  	_ = resp
   163  }
   164  
   165  func ExampleServiceMonitoringClient_GetServiceLevelObjective() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   173  	if err != nil {
   174  		// TODO: Handle error.
   175  	}
   176  	defer c.Close()
   177  
   178  	req := &monitoringpb.GetServiceLevelObjectiveRequest{
   179  		// TODO: Fill request struct fields.
   180  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetServiceLevelObjectiveRequest.
   181  	}
   182  	resp, err := c.GetServiceLevelObjective(ctx, req)
   183  	if err != nil {
   184  		// TODO: Handle error.
   185  	}
   186  	// TODO: Use resp.
   187  	_ = resp
   188  }
   189  
   190  func ExampleServiceMonitoringClient_ListServiceLevelObjectives() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   198  	if err != nil {
   199  		// TODO: Handle error.
   200  	}
   201  	defer c.Close()
   202  
   203  	req := &monitoringpb.ListServiceLevelObjectivesRequest{
   204  		// TODO: Fill request struct fields.
   205  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListServiceLevelObjectivesRequest.
   206  	}
   207  	it := c.ListServiceLevelObjectives(ctx, req)
   208  	for {
   209  		resp, err := it.Next()
   210  		if err == iterator.Done {
   211  			break
   212  		}
   213  		if err != nil {
   214  			// TODO: Handle error.
   215  		}
   216  		// TODO: Use resp.
   217  		_ = resp
   218  
   219  		// If you need to access the underlying RPC response,
   220  		// you can do so by casting the `Response` as below.
   221  		// Otherwise, remove this line. Only populated after
   222  		// first call to Next(). Not safe for concurrent access.
   223  		_ = it.Response.(*monitoringpb.ListServiceLevelObjectivesResponse)
   224  	}
   225  }
   226  
   227  func ExampleServiceMonitoringClient_ListServices() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   235  	if err != nil {
   236  		// TODO: Handle error.
   237  	}
   238  	defer c.Close()
   239  
   240  	req := &monitoringpb.ListServicesRequest{
   241  		// TODO: Fill request struct fields.
   242  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListServicesRequest.
   243  	}
   244  	it := c.ListServices(ctx, req)
   245  	for {
   246  		resp, err := it.Next()
   247  		if err == iterator.Done {
   248  			break
   249  		}
   250  		if err != nil {
   251  			// TODO: Handle error.
   252  		}
   253  		// TODO: Use resp.
   254  		_ = resp
   255  
   256  		// If you need to access the underlying RPC response,
   257  		// you can do so by casting the `Response` as below.
   258  		// Otherwise, remove this line. Only populated after
   259  		// first call to Next(). Not safe for concurrent access.
   260  		_ = it.Response.(*monitoringpb.ListServicesResponse)
   261  	}
   262  }
   263  
   264  func ExampleServiceMonitoringClient_UpdateService() {
   265  	ctx := context.Background()
   266  	// This snippet has been automatically generated and should be regarded as a code template only.
   267  	// It will require modifications to work:
   268  	// - It may require correct/in-range values for request initialization.
   269  	// - It may require specifying regional endpoints when creating the service client as shown in:
   270  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   271  	c, err := monitoring.NewServiceMonitoringClient(ctx)
   272  	if err != nil {
   273  		// TODO: Handle error.
   274  	}
   275  	defer c.Close()
   276  
   277  	req := &monitoringpb.UpdateServiceRequest{
   278  		// TODO: Fill request struct fields.
   279  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#UpdateServiceRequest.
   280  	}
   281  	resp, err := c.UpdateService(ctx, req)
   282  	if err != nil {
   283  		// TODO: Handle error.
   284  	}
   285  	// TODO: Use resp.
   286  	_ = resp
   287  }
   288  
   289  func ExampleServiceMonitoringClient_UpdateServiceLevelObjective() {
   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 := monitoring.NewServiceMonitoringClient(ctx)
   297  	if err != nil {
   298  		// TODO: Handle error.
   299  	}
   300  	defer c.Close()
   301  
   302  	req := &monitoringpb.UpdateServiceLevelObjectiveRequest{
   303  		// TODO: Fill request struct fields.
   304  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#UpdateServiceLevelObjectiveRequest.
   305  	}
   306  	resp, err := c.UpdateServiceLevelObjective(ctx, req)
   307  	if err != nil {
   308  		// TODO: Handle error.
   309  	}
   310  	// TODO: Use resp.
   311  	_ = resp
   312  }
   313  

View as plain text