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 iam_test 18 19 import ( 20 "context" 21 22 iam "cloud.google.com/go/iam/apiv2" 23 iampb "cloud.google.com/go/iam/apiv2/iampb" 24 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 25 "google.golang.org/api/iterator" 26 ) 27 28 func ExampleNewPoliciesClient() { 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 := iam.NewPoliciesClient(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 ExampleNewPoliciesRESTClient() { 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 := iam.NewPoliciesRESTClient(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 ExamplePoliciesClient_CreatePolicy() { 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 := iam.NewPoliciesClient(ctx) 70 if err != nil { 71 // TODO: Handle error. 72 } 73 defer c.Close() 74 75 req := &iampb.CreatePolicyRequest{ 76 // TODO: Fill request struct fields. 77 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv2/iampb#CreatePolicyRequest. 78 } 79 op, err := c.CreatePolicy(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 ExamplePoliciesClient_DeletePolicy() { 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 := iam.NewPoliciesClient(ctx) 100 if err != nil { 101 // TODO: Handle error. 102 } 103 defer c.Close() 104 105 req := &iampb.DeletePolicyRequest{ 106 // TODO: Fill request struct fields. 107 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv2/iampb#DeletePolicyRequest. 108 } 109 op, err := c.DeletePolicy(ctx, req) 110 if err != nil { 111 // TODO: Handle error. 112 } 113 114 resp, err := op.Wait(ctx) 115 if err != nil { 116 // TODO: Handle error. 117 } 118 // TODO: Use resp. 119 _ = resp 120 } 121 122 func ExamplePoliciesClient_GetPolicy() { 123 ctx := context.Background() 124 // This snippet has been automatically generated and should be regarded as a code template only. 125 // It will require modifications to work: 126 // - It may require correct/in-range values for request initialization. 127 // - It may require specifying regional endpoints when creating the service client as shown in: 128 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 129 c, err := iam.NewPoliciesClient(ctx) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 defer c.Close() 134 135 req := &iampb.GetPolicyRequest{ 136 // TODO: Fill request struct fields. 137 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv2/iampb#GetPolicyRequest. 138 } 139 resp, err := c.GetPolicy(ctx, req) 140 if err != nil { 141 // TODO: Handle error. 142 } 143 // TODO: Use resp. 144 _ = resp 145 } 146 147 func ExamplePoliciesClient_ListPolicies() { 148 ctx := context.Background() 149 // This snippet has been automatically generated and should be regarded as a code template only. 150 // It will require modifications to work: 151 // - It may require correct/in-range values for request initialization. 152 // - It may require specifying regional endpoints when creating the service client as shown in: 153 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 154 c, err := iam.NewPoliciesClient(ctx) 155 if err != nil { 156 // TODO: Handle error. 157 } 158 defer c.Close() 159 160 req := &iampb.ListPoliciesRequest{ 161 // TODO: Fill request struct fields. 162 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv2/iampb#ListPoliciesRequest. 163 } 164 it := c.ListPolicies(ctx, req) 165 for { 166 resp, err := it.Next() 167 if err == iterator.Done { 168 break 169 } 170 if err != nil { 171 // TODO: Handle error. 172 } 173 // TODO: Use resp. 174 _ = resp 175 176 // If you need to access the underlying RPC response, 177 // you can do so by casting the `Response` as below. 178 // Otherwise, remove this line. Only populated after 179 // first call to Next(). Not safe for concurrent access. 180 _ = it.Response.(*iampb.ListPoliciesResponse) 181 } 182 } 183 184 func ExamplePoliciesClient_UpdatePolicy() { 185 ctx := context.Background() 186 // This snippet has been automatically generated and should be regarded as a code template only. 187 // It will require modifications to work: 188 // - It may require correct/in-range values for request initialization. 189 // - It may require specifying regional endpoints when creating the service client as shown in: 190 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 191 c, err := iam.NewPoliciesClient(ctx) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 defer c.Close() 196 197 req := &iampb.UpdatePolicyRequest{ 198 // TODO: Fill request struct fields. 199 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv2/iampb#UpdatePolicyRequest. 200 } 201 op, err := c.UpdatePolicy(ctx, req) 202 if err != nil { 203 // TODO: Handle error. 204 } 205 206 resp, err := op.Wait(ctx) 207 if err != nil { 208 // TODO: Handle error. 209 } 210 // TODO: Use resp. 211 _ = resp 212 } 213 214 func ExamplePoliciesClient_GetOperation() { 215 ctx := context.Background() 216 // This snippet has been automatically generated and should be regarded as a code template only. 217 // It will require modifications to work: 218 // - It may require correct/in-range values for request initialization. 219 // - It may require specifying regional endpoints when creating the service client as shown in: 220 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 221 c, err := iam.NewPoliciesClient(ctx) 222 if err != nil { 223 // TODO: Handle error. 224 } 225 defer c.Close() 226 227 req := &longrunningpb.GetOperationRequest{ 228 // TODO: Fill request struct fields. 229 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 230 } 231 resp, err := c.GetOperation(ctx, req) 232 if err != nil { 233 // TODO: Handle error. 234 } 235 // TODO: Use resp. 236 _ = resp 237 } 238