Debian Codegraph @

apikeys/apiv2/api_keys_client_example_test.go

raw
1 // Copyright 2025 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 apikeys_test
18
19 import (
20 "context"
21
22 apikeys "cloud.google.com/go/apikeys/apiv2"
23 apikeyspb "cloud.google.com/go/apikeys/apiv2/apikeyspb"
24 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
25 "google.golang.org/api/iterator"
26 )
27
28 func ExampleNewClient() {
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 := apikeys.NewClient(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 ExampleNewRESTClient() {
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 := apikeys.NewRESTClient(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 ExampleClient_CreateKey() {
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 := apikeys.NewClient(ctx)
70 if err != nil {
71 // TODO: Handle error.
72 }
73 defer c.Close()
74
75 req := &apikeyspb.CreateKeyRequest{
76 // TODO: Fill request struct fields.
77 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#CreateKeyRequest.
78 }
79 op, err := c.CreateKey(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 ExampleClient_DeleteKey() {
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 := apikeys.NewClient(ctx)
100 if err != nil {
101 // TODO: Handle error.
102 }
103 defer c.Close()
104
105 req := &apikeyspb.DeleteKeyRequest{
106 // TODO: Fill request struct fields.
107 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#DeleteKeyRequest.
108 }
109 op, err := c.DeleteKey(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 ExampleClient_GetKey() {
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 := apikeys.NewClient(ctx)
130 if err != nil {
131 // TODO: Handle error.
132 }
133 defer c.Close()
134
135 req := &apikeyspb.GetKeyRequest{
136 // TODO: Fill request struct fields.
137 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#GetKeyRequest.
138 }
139 resp, err := c.GetKey(ctx, req)
140 if err != nil {
141 // TODO: Handle error.
142 }
143 // TODO: Use resp.
144 _ = resp
145 }
146
147 func ExampleClient_GetKeyString() {
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 := apikeys.NewClient(ctx)
155 if err != nil {
156 // TODO: Handle error.
157 }
158 defer c.Close()
159
160 req := &apikeyspb.GetKeyStringRequest{
161 // TODO: Fill request struct fields.
162 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#GetKeyStringRequest.
163 }
164 resp, err := c.GetKeyString(ctx, req)
165 if err != nil {
166 // TODO: Handle error.
167 }
168 // TODO: Use resp.
169 _ = resp
170 }
171
172 func ExampleClient_ListKeys() {
173 ctx := context.Background()
174 // This snippet has been automatically generated and should be regarded as a code template only.
175 // It will require modifications to work:
176 // - It may require correct/in-range values for request initialization.
177 // - It may require specifying regional endpoints when creating the service client as shown in:
178 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
179 c, err := apikeys.NewClient(ctx)
180 if err != nil {
181 // TODO: Handle error.
182 }
183 defer c.Close()
184
185 req := &apikeyspb.ListKeysRequest{
186 // TODO: Fill request struct fields.
187 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#ListKeysRequest.
188 }
189 it := c.ListKeys(ctx, req)
190 for {
191 resp, err := it.Next()
192 if err == iterator.Done {
193 break
194 }
195 if err != nil {
196 // TODO: Handle error.
197 }
198 // TODO: Use resp.
199 _ = resp
200
201 // If you need to access the underlying RPC response,
202 // you can do so by casting the `Response` as below.
203 // Otherwise, remove this line. Only populated after
204 // first call to Next(). Not safe for concurrent access.
205 _ = it.Response.(*apikeyspb.ListKeysResponse)
206 }
207 }
208
209 func ExampleClient_LookupKey() {
210 ctx := context.Background()
211 // This snippet has been automatically generated and should be regarded as a code template only.
212 // It will require modifications to work:
213 // - It may require correct/in-range values for request initialization.
214 // - It may require specifying regional endpoints when creating the service client as shown in:
215 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
216 c, err := apikeys.NewClient(ctx)
217 if err != nil {
218 // TODO: Handle error.
219 }
220 defer c.Close()
221
222 req := &apikeyspb.LookupKeyRequest{
223 // TODO: Fill request struct fields.
224 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#LookupKeyRequest.
225 }
226 resp, err := c.LookupKey(ctx, req)
227 if err != nil {
228 // TODO: Handle error.
229 }
230 // TODO: Use resp.
231 _ = resp
232 }
233
234 func ExampleClient_UndeleteKey() {
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 := apikeys.NewClient(ctx)
242 if err != nil {
243 // TODO: Handle error.
244 }
245 defer c.Close()
246
247 req := &apikeyspb.UndeleteKeyRequest{
248 // TODO: Fill request struct fields.
249 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#UndeleteKeyRequest.
250 }
251 op, err := c.UndeleteKey(ctx, req)
252 if err != nil {
253 // TODO: Handle error.
254 }
255
256 resp, err := op.Wait(ctx)
257 if err != nil {
258 // TODO: Handle error.
259 }
260 // TODO: Use resp.
261 _ = resp
262 }
263
264 func ExampleClient_UpdateKey() {
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 := apikeys.NewClient(ctx)
272 if err != nil {
273 // TODO: Handle error.
274 }
275 defer c.Close()
276
277 req := &apikeyspb.UpdateKeyRequest{
278 // TODO: Fill request struct fields.
279 // See https://pkg.go.dev/cloud.google.com/go/apikeys/apiv2/apikeyspb#UpdateKeyRequest.
280 }
281 op, err := c.UpdateKey(ctx, req)
282 if err != nil {
283 // TODO: Handle error.
284 }
285
286 resp, err := op.Wait(ctx)
287 if err != nil {
288 // TODO: Handle error.
289 }
290 // TODO: Use resp.
291 _ = resp
292 }
293
294 func ExampleClient_GetOperation() {
295 ctx := context.Background()
296 // This snippet has been automatically generated and should be regarded as a code template only.
297 // It will require modifications to work:
298 // - It may require correct/in-range values for request initialization.
299 // - It may require specifying regional endpoints when creating the service client as shown in:
300 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
301 c, err := apikeys.NewClient(ctx)
302 if err != nil {
303 // TODO: Handle error.
304 }
305 defer c.Close()
306
307 req := &longrunningpb.GetOperationRequest{
308 // TODO: Fill request struct fields.
309 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
310 }
311 resp, err := c.GetOperation(ctx, req)
312 if err != nil {
313 // TODO: Handle error.
314 }
315 // TODO: Use resp.
316 _ = resp
317 }