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 resourcemanager "cloud.google.com/go/resourcemanager/apiv2" 24 resourcemanagerpb "cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb" 25 "google.golang.org/api/iterator" 26 ) 27 28 func ExampleNewFoldersClient() { 29 ctx := context.Background() 30 // This snippet has been automatically generated and should be regarded as a code template only. 31 // It will require modifications to work: 32 // - It may require correct/in-range values for request initialization. 33 // - It may require specifying regional endpoints when creating the service client as shown in: 34 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 35 c, err := resourcemanager.NewFoldersClient(ctx) 36 if err != nil { 37 // TODO: Handle error. 38 } 39 defer c.Close() 40 41 // TODO: Use client. 42 _ = c 43 } 44 45 func ExampleNewFoldersRESTClient() { 46 ctx := context.Background() 47 // This snippet has been automatically generated and should be regarded as a code template only. 48 // It will require modifications to work: 49 // - It may require correct/in-range values for request initialization. 50 // - It may require specifying regional endpoints when creating the service client as shown in: 51 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 52 c, err := resourcemanager.NewFoldersRESTClient(ctx) 53 if err != nil { 54 // TODO: Handle error. 55 } 56 defer c.Close() 57 58 // TODO: Use client. 59 _ = c 60 } 61 62 func ExampleFoldersClient_CreateFolder() { 63 ctx := context.Background() 64 // This snippet has been automatically generated and should be regarded as a code template only. 65 // It will require modifications to work: 66 // - It may require correct/in-range values for request initialization. 67 // - It may require specifying regional endpoints when creating the service client as shown in: 68 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 69 c, err := resourcemanager.NewFoldersClient(ctx) 70 if err != nil { 71 // TODO: Handle error. 72 } 73 defer c.Close() 74 75 req := &resourcemanagerpb.CreateFolderRequest{ 76 // TODO: Fill request struct fields. 77 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#CreateFolderRequest. 78 } 79 op, err := c.CreateFolder(ctx, req) 80 if err != nil { 81 // TODO: Handle error. 82 } 83 84 resp, err := op.Wait(ctx) 85 if err != nil { 86 // TODO: Handle error. 87 } 88 // TODO: Use resp. 89 _ = resp 90 } 91 92 func ExampleFoldersClient_DeleteFolder() { 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 := resourcemanager.NewFoldersClient(ctx) 100 if err != nil { 101 // TODO: Handle error. 102 } 103 defer c.Close() 104 105 req := &resourcemanagerpb.DeleteFolderRequest{ 106 // TODO: Fill request struct fields. 107 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#DeleteFolderRequest. 108 } 109 resp, err := c.DeleteFolder(ctx, req) 110 if err != nil { 111 // TODO: Handle error. 112 } 113 // TODO: Use resp. 114 _ = resp 115 } 116 117 func ExampleFoldersClient_GetFolder() { 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 := resourcemanager.NewFoldersClient(ctx) 125 if err != nil { 126 // TODO: Handle error. 127 } 128 defer c.Close() 129 130 req := &resourcemanagerpb.GetFolderRequest{ 131 // TODO: Fill request struct fields. 132 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#GetFolderRequest. 133 } 134 resp, err := c.GetFolder(ctx, req) 135 if err != nil { 136 // TODO: Handle error. 137 } 138 // TODO: Use resp. 139 _ = resp 140 } 141 142 func ExampleFoldersClient_GetIamPolicy() { 143 ctx := context.Background() 144 // This snippet has been automatically generated and should be regarded as a code template only. 145 // It will require modifications to work: 146 // - It may require correct/in-range values for request initialization. 147 // - It may require specifying regional endpoints when creating the service client as shown in: 148 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 149 c, err := resourcemanager.NewFoldersClient(ctx) 150 if err != nil { 151 // TODO: Handle error. 152 } 153 defer c.Close() 154 155 req := &iampb.GetIamPolicyRequest{ 156 // TODO: Fill request struct fields. 157 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 158 } 159 resp, err := c.GetIamPolicy(ctx, req) 160 if err != nil { 161 // TODO: Handle error. 162 } 163 // TODO: Use resp. 164 _ = resp 165 } 166 167 func ExampleFoldersClient_ListFolders() { 168 ctx := context.Background() 169 // This snippet has been automatically generated and should be regarded as a code template only. 170 // It will require modifications to work: 171 // - It may require correct/in-range values for request initialization. 172 // - It may require specifying regional endpoints when creating the service client as shown in: 173 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 174 c, err := resourcemanager.NewFoldersClient(ctx) 175 if err != nil { 176 // TODO: Handle error. 177 } 178 defer c.Close() 179 180 req := &resourcemanagerpb.ListFoldersRequest{ 181 // TODO: Fill request struct fields. 182 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#ListFoldersRequest. 183 } 184 it := c.ListFolders(ctx, req) 185 for { 186 resp, err := it.Next() 187 if err == iterator.Done { 188 break 189 } 190 if err != nil { 191 // TODO: Handle error. 192 } 193 // TODO: Use resp. 194 _ = resp 195 196 // If you need to access the underlying RPC response, 197 // you can do so by casting the `Response` as below. 198 // Otherwise, remove this line. Only populated after 199 // first call to Next(). Not safe for concurrent access. 200 _ = it.Response.(*resourcemanagerpb.ListFoldersResponse) 201 } 202 } 203 204 func ExampleFoldersClient_MoveFolder() { 205 ctx := context.Background() 206 // This snippet has been automatically generated and should be regarded as a code template only. 207 // It will require modifications to work: 208 // - It may require correct/in-range values for request initialization. 209 // - It may require specifying regional endpoints when creating the service client as shown in: 210 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 211 c, err := resourcemanager.NewFoldersClient(ctx) 212 if err != nil { 213 // TODO: Handle error. 214 } 215 defer c.Close() 216 217 req := &resourcemanagerpb.MoveFolderRequest{ 218 // TODO: Fill request struct fields. 219 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#MoveFolderRequest. 220 } 221 op, err := c.MoveFolder(ctx, req) 222 if err != nil { 223 // TODO: Handle error. 224 } 225 226 resp, err := op.Wait(ctx) 227 if err != nil { 228 // TODO: Handle error. 229 } 230 // TODO: Use resp. 231 _ = resp 232 } 233 234 func ExampleFoldersClient_SearchFolders() { 235 ctx := context.Background() 236 // This snippet has been automatically generated and should be regarded as a code template only. 237 // It will require modifications to work: 238 // - It may require correct/in-range values for request initialization. 239 // - It may require specifying regional endpoints when creating the service client as shown in: 240 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 241 c, err := resourcemanager.NewFoldersClient(ctx) 242 if err != nil { 243 // TODO: Handle error. 244 } 245 defer c.Close() 246 247 req := &resourcemanagerpb.SearchFoldersRequest{ 248 // TODO: Fill request struct fields. 249 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#SearchFoldersRequest. 250 } 251 it := c.SearchFolders(ctx, req) 252 for { 253 resp, err := it.Next() 254 if err == iterator.Done { 255 break 256 } 257 if err != nil { 258 // TODO: Handle error. 259 } 260 // TODO: Use resp. 261 _ = resp 262 263 // If you need to access the underlying RPC response, 264 // you can do so by casting the `Response` as below. 265 // Otherwise, remove this line. Only populated after 266 // first call to Next(). Not safe for concurrent access. 267 _ = it.Response.(*resourcemanagerpb.SearchFoldersResponse) 268 } 269 } 270 271 func ExampleFoldersClient_SetIamPolicy() { 272 ctx := context.Background() 273 // This snippet has been automatically generated and should be regarded as a code template only. 274 // It will require modifications to work: 275 // - It may require correct/in-range values for request initialization. 276 // - It may require specifying regional endpoints when creating the service client as shown in: 277 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 278 c, err := resourcemanager.NewFoldersClient(ctx) 279 if err != nil { 280 // TODO: Handle error. 281 } 282 defer c.Close() 283 284 req := &iampb.SetIamPolicyRequest{ 285 // TODO: Fill request struct fields. 286 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 287 } 288 resp, err := c.SetIamPolicy(ctx, req) 289 if err != nil { 290 // TODO: Handle error. 291 } 292 // TODO: Use resp. 293 _ = resp 294 } 295 296 func ExampleFoldersClient_TestIamPermissions() { 297 ctx := context.Background() 298 // This snippet has been automatically generated and should be regarded as a code template only. 299 // It will require modifications to work: 300 // - It may require correct/in-range values for request initialization. 301 // - It may require specifying regional endpoints when creating the service client as shown in: 302 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 303 c, err := resourcemanager.NewFoldersClient(ctx) 304 if err != nil { 305 // TODO: Handle error. 306 } 307 defer c.Close() 308 309 req := &iampb.TestIamPermissionsRequest{ 310 // TODO: Fill request struct fields. 311 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 312 } 313 resp, err := c.TestIamPermissions(ctx, req) 314 if err != nil { 315 // TODO: Handle error. 316 } 317 // TODO: Use resp. 318 _ = resp 319 } 320 321 func ExampleFoldersClient_UndeleteFolder() { 322 ctx := context.Background() 323 // This snippet has been automatically generated and should be regarded as a code template only. 324 // It will require modifications to work: 325 // - It may require correct/in-range values for request initialization. 326 // - It may require specifying regional endpoints when creating the service client as shown in: 327 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 328 c, err := resourcemanager.NewFoldersClient(ctx) 329 if err != nil { 330 // TODO: Handle error. 331 } 332 defer c.Close() 333 334 req := &resourcemanagerpb.UndeleteFolderRequest{ 335 // TODO: Fill request struct fields. 336 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#UndeleteFolderRequest. 337 } 338 resp, err := c.UndeleteFolder(ctx, req) 339 if err != nil { 340 // TODO: Handle error. 341 } 342 // TODO: Use resp. 343 _ = resp 344 } 345 346 func ExampleFoldersClient_UpdateFolder() { 347 ctx := context.Background() 348 // This snippet has been automatically generated and should be regarded as a code template only. 349 // It will require modifications to work: 350 // - It may require correct/in-range values for request initialization. 351 // - It may require specifying regional endpoints when creating the service client as shown in: 352 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 353 c, err := resourcemanager.NewFoldersClient(ctx) 354 if err != nil { 355 // TODO: Handle error. 356 } 357 defer c.Close() 358 359 req := &resourcemanagerpb.UpdateFolderRequest{ 360 // TODO: Fill request struct fields. 361 // See https://pkg.go.dev/cloud.google.com/go/resourcemanager/apiv2/resourcemanagerpb#UpdateFolderRequest. 362 } 363 resp, err := c.UpdateFolder(ctx, req) 364 if err != nil { 365 // TODO: Handle error. 366 } 367 // TODO: Use resp. 368 _ = resp 369 } 370