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 resourcemanager_test 18 19 import ( 20 "context" 21 22 iampb "cloud.google.com/go/iam/apiv1/iampb" 23 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 24 resourcemanager "cloud.google.com/go/resourcemanager/apiv3" 25 resourcemanagerpb "cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb" 26 "google.golang.org/api/iterator" 27 ) 28 29 func ExampleNewProjectsClient() { 30 ctx := context.Background() 31 // This snippet has been automatically generated and should be regarded as a code template only. 32 // It will require modifications to work: 33 // - It may require correct/in-range values for request initialization. 34 // - It may require specifying regional endpoints when creating the service client as shown in: 35 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 36 c, err := resourcemanager.NewProjectsClient(ctx) 37 if err != nil { 38 // TODO: Handle error. 39 } 40 defer c.Close() 41 42 // TODO: Use client. 43 _ = c 44 } 45 46 func ExampleNewProjectsRESTClient() { 47 ctx := context.Background() 48 // This snippet has been automatically generated and should be regarded as a code template only. 49 // It will require modifications to work: 50 // - It may require correct/in-range values for request initialization. 51 // - It may require specifying regional endpoints when creating the service client as shown in: 52 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 53 c, err := resourcemanager.NewProjectsRESTClient(ctx) 54 if err != nil { 55 // TODO: Handle error. 56 } 57 defer c.Close() 58 59 // TODO: Use client. 60 _ = c 61 } 62 63 func ExampleProjectsClient_CreateProject() { 64 ctx := context.Background() 65 // This snippet has been automatically generated and should be regarded as a code template only. 66 // It will require modifications to work: 67 // - It may require correct/in-range values for request initialization. 68 // - It may require specifying regional endpoints when creating the service client as shown in: 69 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 70 c, err := resourcemanager.NewProjectsClient(ctx) 71 if err != nil { 72 // TODO: Handle error. 73 } 74 defer c.Close() 75 76 req := &resourcemanagerpb.CreateProjectRequest{ 77 // TODO: Fill request struct fields. 78 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#CreateProjectRequest. 79 } 80 op, err := c.CreateProject(ctx, req) 81 if err != nil { 82 // TODO: Handle error. 83 } 84 85 resp, err := op.Wait(ctx) 86 if err != nil { 87 // TODO: Handle error. 88 } 89 // TODO: Use resp. 90 _ = resp 91 } 92 93 func ExampleProjectsClient_DeleteProject() { 94 ctx := context.Background() 95 // This snippet has been automatically generated and should be regarded as a code template only. 96 // It will require modifications to work: 97 // - It may require correct/in-range values for request initialization. 98 // - It may require specifying regional endpoints when creating the service client as shown in: 99 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 100 c, err := resourcemanager.NewProjectsClient(ctx) 101 if err != nil { 102 // TODO: Handle error. 103 } 104 defer c.Close() 105 106 req := &resourcemanagerpb.DeleteProjectRequest{ 107 // TODO: Fill request struct fields. 108 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#DeleteProjectRequest. 109 } 110 op, err := c.DeleteProject(ctx, req) 111 if err != nil { 112 // TODO: Handle error. 113 } 114 115 resp, err := op.Wait(ctx) 116 if err != nil { 117 // TODO: Handle error. 118 } 119 // TODO: Use resp. 120 _ = resp 121 } 122 123 func ExampleProjectsClient_GetIamPolicy() { 124 ctx := context.Background() 125 // This snippet has been automatically generated and should be regarded as a code template only. 126 // It will require modifications to work: 127 // - It may require correct/in-range values for request initialization. 128 // - It may require specifying regional endpoints when creating the service client as shown in: 129 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 130 c, err := resourcemanager.NewProjectsClient(ctx) 131 if err != nil { 132 // TODO: Handle error. 133 } 134 defer c.Close() 135 136 req := &iampb.GetIamPolicyRequest{ 137 // TODO: Fill request struct fields. 138 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 139 } 140 resp, err := c.GetIamPolicy(ctx, req) 141 if err != nil { 142 // TODO: Handle error. 143 } 144 // TODO: Use resp. 145 _ = resp 146 } 147 148 func ExampleProjectsClient_GetProject() { 149 ctx := context.Background() 150 // This snippet has been automatically generated and should be regarded as a code template only. 151 // It will require modifications to work: 152 // - It may require correct/in-range values for request initialization. 153 // - It may require specifying regional endpoints when creating the service client as shown in: 154 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 155 c, err := resourcemanager.NewProjectsClient(ctx) 156 if err != nil { 157 // TODO: Handle error. 158 } 159 defer c.Close() 160 161 req := &resourcemanagerpb.GetProjectRequest{ 162 // TODO: Fill request struct fields. 163 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#GetProjectRequest. 164 } 165 resp, err := c.GetProject(ctx, req) 166 if err != nil { 167 // TODO: Handle error. 168 } 169 // TODO: Use resp. 170 _ = resp 171 } 172 173 func ExampleProjectsClient_ListProjects() { 174 ctx := context.Background() 175 // This snippet has been automatically generated and should be regarded as a code template only. 176 // It will require modifications to work: 177 // - It may require correct/in-range values for request initialization. 178 // - It may require specifying regional endpoints when creating the service client as shown in: 179 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 180 c, err := resourcemanager.NewProjectsClient(ctx) 181 if err != nil { 182 // TODO: Handle error. 183 } 184 defer c.Close() 185 186 req := &resourcemanagerpb.ListProjectsRequest{ 187 // TODO: Fill request struct fields. 188 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#ListProjectsRequest. 189 } 190 it := c.ListProjects(ctx, req) 191 for { 192 resp, err := it.Next() 193 if err == iterator.Done { 194 break 195 } 196 if err != nil { 197 // TODO: Handle error. 198 } 199 // TODO: Use resp. 200 _ = resp 201 202 // If you need to access the underlying RPC response, 203 // you can do so by casting the `Response` as below. 204 // Otherwise, remove this line. Only populated after 205 // first call to Next(). Not safe for concurrent access. 206 _ = it.Response.(*resourcemanagerpb.ListProjectsResponse) 207 } 208 } 209 210 func ExampleProjectsClient_MoveProject() { 211 ctx := context.Background() 212 // This snippet has been automatically generated and should be regarded as a code template only. 213 // It will require modifications to work: 214 // - It may require correct/in-range values for request initialization. 215 // - It may require specifying regional endpoints when creating the service client as shown in: 216 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 217 c, err := resourcemanager.NewProjectsClient(ctx) 218 if err != nil { 219 // TODO: Handle error. 220 } 221 defer c.Close() 222 223 req := &resourcemanagerpb.MoveProjectRequest{ 224 // TODO: Fill request struct fields. 225 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#MoveProjectRequest. 226 } 227 op, err := c.MoveProject(ctx, req) 228 if err != nil { 229 // TODO: Handle error. 230 } 231 232 resp, err := op.Wait(ctx) 233 if err != nil { 234 // TODO: Handle error. 235 } 236 // TODO: Use resp. 237 _ = resp 238 } 239 240 func ExampleProjectsClient_SearchProjects() { 241 ctx := context.Background() 242 // This snippet has been automatically generated and should be regarded as a code template only. 243 // It will require modifications to work: 244 // - It may require correct/in-range values for request initialization. 245 // - It may require specifying regional endpoints when creating the service client as shown in: 246 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 247 c, err := resourcemanager.NewProjectsClient(ctx) 248 if err != nil { 249 // TODO: Handle error. 250 } 251 defer c.Close() 252 253 req := &resourcemanagerpb.SearchProjectsRequest{ 254 // TODO: Fill request struct fields. 255 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#SearchProjectsRequest. 256 } 257 it := c.SearchProjects(ctx, req) 258 for { 259 resp, err := it.Next() 260 if err == iterator.Done { 261 break 262 } 263 if err != nil { 264 // TODO: Handle error. 265 } 266 // TODO: Use resp. 267 _ = resp 268 269 // If you need to access the underlying RPC response, 270 // you can do so by casting the `Response` as below. 271 // Otherwise, remove this line. Only populated after 272 // first call to Next(). Not safe for concurrent access. 273 _ = it.Response.(*resourcemanagerpb.SearchProjectsResponse) 274 } 275 } 276 277 func ExampleProjectsClient_SetIamPolicy() { 278 ctx := context.Background() 279 // This snippet has been automatically generated and should be regarded as a code template only. 280 // It will require modifications to work: 281 // - It may require correct/in-range values for request initialization. 282 // - It may require specifying regional endpoints when creating the service client as shown in: 283 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 284 c, err := resourcemanager.NewProjectsClient(ctx) 285 if err != nil { 286 // TODO: Handle error. 287 } 288 defer c.Close() 289 290 req := &iampb.SetIamPolicyRequest{ 291 // TODO: Fill request struct fields. 292 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 293 } 294 resp, err := c.SetIamPolicy(ctx, req) 295 if err != nil { 296 // TODO: Handle error. 297 } 298 // TODO: Use resp. 299 _ = resp 300 } 301 302 func ExampleProjectsClient_TestIamPermissions() { 303 ctx := context.Background() 304 // This snippet has been automatically generated and should be regarded as a code template only. 305 // It will require modifications to work: 306 // - It may require correct/in-range values for request initialization. 307 // - It may require specifying regional endpoints when creating the service client as shown in: 308 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 309 c, err := resourcemanager.NewProjectsClient(ctx) 310 if err != nil { 311 // TODO: Handle error. 312 } 313 defer c.Close() 314 315 req := &iampb.TestIamPermissionsRequest{ 316 // TODO: Fill request struct fields. 317 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 318 } 319 resp, err := c.TestIamPermissions(ctx, req) 320 if err != nil { 321 // TODO: Handle error. 322 } 323 // TODO: Use resp. 324 _ = resp 325 } 326 327 func ExampleProjectsClient_UndeleteProject() { 328 ctx := context.Background() 329 // This snippet has been automatically generated and should be regarded as a code template only. 330 // It will require modifications to work: 331 // - It may require correct/in-range values for request initialization. 332 // - It may require specifying regional endpoints when creating the service client as shown in: 333 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 334 c, err := resourcemanager.NewProjectsClient(ctx) 335 if err != nil { 336 // TODO: Handle error. 337 } 338 defer c.Close() 339 340 req := &resourcemanagerpb.UndeleteProjectRequest{ 341 // TODO: Fill request struct fields. 342 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#UndeleteProjectRequest. 343 } 344 op, err := c.UndeleteProject(ctx, req) 345 if err != nil { 346 // TODO: Handle error. 347 } 348 349 resp, err := op.Wait(ctx) 350 if err != nil { 351 // TODO: Handle error. 352 } 353 // TODO: Use resp. 354 _ = resp 355 } 356 357 func ExampleProjectsClient_UpdateProject() { 358 ctx := context.Background() 359 // This snippet has been automatically generated and should be regarded as a code template only. 360 // It will require modifications to work: 361 // - It may require correct/in-range values for request initialization. 362 // - It may require specifying regional endpoints when creating the service client as shown in: 363 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 364 c, err := resourcemanager.NewProjectsClient(ctx) 365 if err != nil { 366 // TODO: Handle error. 367 } 368 defer c.Close() 369 370 req := &resourcemanagerpb.UpdateProjectRequest{ 371 // TODO: Fill request struct fields. 372 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb#UpdateProjectRequest. 373 } 374 op, err := c.UpdateProject(ctx, req) 375 if err != nil { 376 // TODO: Handle error. 377 } 378 379 resp, err := op.Wait(ctx) 380 if err != nil { 381 // TODO: Handle error. 382 } 383 // TODO: Use resp. 384 _ = resp 385 } 386 387 func ExampleProjectsClient_GetOperation() { 388 ctx := context.Background() 389 // This snippet has been automatically generated and should be regarded as a code template only. 390 // It will require modifications to work: 391 // - It may require correct/in-range values for request initialization. 392 // - It may require specifying regional endpoints when creating the service client as shown in: 393 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 394 c, err := resourcemanager.NewProjectsClient(ctx) 395 if err != nil { 396 // TODO: Handle error. 397 } 398 defer c.Close() 399 400 req := &longrunningpb.GetOperationRequest{ 401 // TODO: Fill request struct fields. 402 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 403 } 404 resp, err := c.GetOperation(ctx, req) 405 if err != nil { 406 // TODO: Handle error. 407 } 408 // TODO: Use resp. 409 _ = resp 410 } 411