Debian Codegraph @

apihub/apiv1/api_hub_collect_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 apihub_test
18
19 import (
20 "context"
21
22 apihub "cloud.google.com/go/apihub/apiv1"
23 apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb"
24 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
25 "google.golang.org/api/iterator"
26 locationpb "google.golang.org/genproto/googleapis/cloud/location"
27 )
28
29 func ExampleNewApiHubCollectRESTClient() {
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 := apihub.NewApiHubCollectRESTClient(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 ExampleApiHubCollectClient_CollectApiData() {
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 := apihub.NewApiHubCollectRESTClient(ctx)
54 if err != nil {
55 // TODO: Handle error.
56 }
57 defer c.Close()
58
59 req := &apihubpb.CollectApiDataRequest{
60 // TODO: Fill request struct fields.
61 // See https://pkg.go.dev/cloud.google.com/go/apihub/apiv1/apihubpb#CollectApiDataRequest.
62 }
63 op, err := c.CollectApiData(ctx, req)
64 if err != nil {
65 // TODO: Handle error.
66 }
67
68 resp, err := op.Wait(ctx)
69 if err != nil {
70 // TODO: Handle error.
71 }
72 // TODO: Use resp.
73 _ = resp
74 }
75
76 func ExampleApiHubCollectClient_GetLocation() {
77 ctx := context.Background()
78 // This snippet has been automatically generated and should be regarded as a code template only.
79 // It will require modifications to work:
80 // - It may require correct/in-range values for request initialization.
81 // - It may require specifying regional endpoints when creating the service client as shown in:
82 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
83 c, err := apihub.NewApiHubCollectRESTClient(ctx)
84 if err != nil {
85 // TODO: Handle error.
86 }
87 defer c.Close()
88
89 req := &locationpb.GetLocationRequest{
90 // TODO: Fill request struct fields.
91 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
92 }
93 resp, err := c.GetLocation(ctx, req)
94 if err != nil {
95 // TODO: Handle error.
96 }
97 // TODO: Use resp.
98 _ = resp
99 }
100
101 func ExampleApiHubCollectClient_ListLocations() {
102 ctx := context.Background()
103 // This snippet has been automatically generated and should be regarded as a code template only.
104 // It will require modifications to work:
105 // - It may require correct/in-range values for request initialization.
106 // - It may require specifying regional endpoints when creating the service client as shown in:
107 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
108 c, err := apihub.NewApiHubCollectRESTClient(ctx)
109 if err != nil {
110 // TODO: Handle error.
111 }
112 defer c.Close()
113
114 req := &locationpb.ListLocationsRequest{
115 // TODO: Fill request struct fields.
116 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
117 }
118 it := c.ListLocations(ctx, req)
119 for {
120 resp, err := it.Next()
121 if err == iterator.Done {
122 break
123 }
124 if err != nil {
125 // TODO: Handle error.
126 }
127 // TODO: Use resp.
128 _ = resp
129
130 // If you need to access the underlying RPC response,
131 // you can do so by casting the `Response` as below.
132 // Otherwise, remove this line. Only populated after
133 // first call to Next(). Not safe for concurrent access.
134 _ = it.Response.(*locationpb.ListLocationsResponse)
135 }
136 }
137
138 func ExampleApiHubCollectClient_CancelOperation() {
139 ctx := context.Background()
140 // This snippet has been automatically generated and should be regarded as a code template only.
141 // It will require modifications to work:
142 // - It may require correct/in-range values for request initialization.
143 // - It may require specifying regional endpoints when creating the service client as shown in:
144 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
145 c, err := apihub.NewApiHubCollectRESTClient(ctx)
146 if err != nil {
147 // TODO: Handle error.
148 }
149 defer c.Close()
150
151 req := &longrunningpb.CancelOperationRequest{
152 // TODO: Fill request struct fields.
153 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
154 }
155 err = c.CancelOperation(ctx, req)
156 if err != nil {
157 // TODO: Handle error.
158 }
159 }
160
161 func ExampleApiHubCollectClient_DeleteOperation() {
162 ctx := context.Background()
163 // This snippet has been automatically generated and should be regarded as a code template only.
164 // It will require modifications to work:
165 // - It may require correct/in-range values for request initialization.
166 // - It may require specifying regional endpoints when creating the service client as shown in:
167 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
168 c, err := apihub.NewApiHubCollectRESTClient(ctx)
169 if err != nil {
170 // TODO: Handle error.
171 }
172 defer c.Close()
173
174 req := &longrunningpb.DeleteOperationRequest{
175 // TODO: Fill request struct fields.
176 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
177 }
178 err = c.DeleteOperation(ctx, req)
179 if err != nil {
180 // TODO: Handle error.
181 }
182 }
183
184 func ExampleApiHubCollectClient_GetOperation() {
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 := apihub.NewApiHubCollectRESTClient(ctx)
192 if err != nil {
193 // TODO: Handle error.
194 }
195 defer c.Close()
196
197 req := &longrunningpb.GetOperationRequest{
198 // TODO: Fill request struct fields.
199 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
200 }
201 resp, err := c.GetOperation(ctx, req)
202 if err != nil {
203 // TODO: Handle error.
204 }
205 // TODO: Use resp.
206 _ = resp
207 }
208
209 func ExampleApiHubCollectClient_ListOperations() {
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 := apihub.NewApiHubCollectRESTClient(ctx)
217 if err != nil {
218 // TODO: Handle error.
219 }
220 defer c.Close()
221
222 req := &longrunningpb.ListOperationsRequest{
223 // TODO: Fill request struct fields.
224 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
225 }
226 it := c.ListOperations(ctx, req)
227 for {
228 resp, err := it.Next()
229 if err == iterator.Done {
230 break
231 }
232 if err != nil {
233 // TODO: Handle error.
234 }
235 // TODO: Use resp.
236 _ = resp
237
238 // If you need to access the underlying RPC response,
239 // you can do so by casting the `Response` as below.
240 // Otherwise, remove this line. Only populated after
241 // first call to Next(). Not safe for concurrent access.
242 _ = it.Response.(*longrunningpb.ListOperationsResponse)
243 }
244 }