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 ExampleNewAlertPolicyClient() { 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.NewAlertPolicyClient(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 ExampleAlertPolicyClient_CreateAlertPolicy() { 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.NewAlertPolicyClient(ctx) 52 if err != nil { 53 // TODO: Handle error. 54 } 55 defer c.Close() 56 57 req := &monitoringpb.CreateAlertPolicyRequest{ 58 // TODO: Fill request struct fields. 59 // See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateAlertPolicyRequest. 60 } 61 resp, err := c.CreateAlertPolicy(ctx, req) 62 if err != nil { 63 // TODO: Handle error. 64 } 65 // TODO: Use resp. 66 _ = resp 67 } 68 69 func ExampleAlertPolicyClient_DeleteAlertPolicy() { 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.NewAlertPolicyClient(ctx) 77 if err != nil { 78 // TODO: Handle error. 79 } 80 defer c.Close() 81 82 req := &monitoringpb.DeleteAlertPolicyRequest{ 83 // TODO: Fill request struct fields. 84 // See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#DeleteAlertPolicyRequest. 85 } 86 err = c.DeleteAlertPolicy(ctx, req) 87 if err != nil { 88 // TODO: Handle error. 89 } 90 } 91 92 func ExampleAlertPolicyClient_GetAlertPolicy() { 93 ctx := context.Background() 94 // This snippet has been automatically generated and should be regarded as a code template only. 95 // It will require modifications to work: 96 // - It may require correct/in-range values for request initialization. 97 // - It may require specifying regional endpoints when creating the service client as shown in: 98 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 99 c, err := monitoring.NewAlertPolicyClient(ctx) 100 if err != nil { 101 // TODO: Handle error. 102 } 103 defer c.Close() 104 105 req := &monitoringpb.GetAlertPolicyRequest{ 106 // TODO: Fill request struct fields. 107 // See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetAlertPolicyRequest. 108 } 109 resp, err := c.GetAlertPolicy(ctx, req) 110 if err != nil { 111 // TODO: Handle error. 112 } 113 // TODO: Use resp. 114 _ = resp 115 } 116 117 func ExampleAlertPolicyClient_ListAlertPolicies() { 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.NewAlertPolicyClient(ctx) 125 if err != nil { 126 // TODO: Handle error. 127 } 128 defer c.Close() 129 130 req := &monitoringpb.ListAlertPoliciesRequest{ 131 // TODO: Fill request struct fields. 132 // See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListAlertPoliciesRequest. 133 } 134 it := c.ListAlertPolicies(ctx, req) 135 for { 136 resp, err := it.Next() 137 if err == iterator.Done { 138 break 139 } 140 if err != nil { 141 // TODO: Handle error. 142 } 143 // TODO: Use resp. 144 _ = resp 145 146 // If you need to access the underlying RPC response, 147 // you can do so by casting the `Response` as below. 148 // Otherwise, remove this line. Only populated after 149 // first call to Next(). Not safe for concurrent access. 150 _ = it.Response.(*monitoringpb.ListAlertPoliciesResponse) 151 } 152 } 153 154 func ExampleAlertPolicyClient_UpdateAlertPolicy() { 155 ctx := context.Background() 156 // This snippet has been automatically generated and should be regarded as a code template only. 157 // It will require modifications to work: 158 // - It may require correct/in-range values for request initialization. 159 // - It may require specifying regional endpoints when creating the service client as shown in: 160 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 161 c, err := monitoring.NewAlertPolicyClient(ctx) 162 if err != nil { 163 // TODO: Handle error. 164 } 165 defer c.Close() 166 167 req := &monitoringpb.UpdateAlertPolicyRequest{ 168 // TODO: Fill request struct fields. 169 // See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#UpdateAlertPolicyRequest. 170 } 171 resp, err := c.UpdateAlertPolicy(ctx, req) 172 if err != nil { 173 // TODO: Handle error. 174 } 175 // TODO: Use resp. 176 _ = resp 177 } 178