| 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 visionai_test |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"io" |
| 22 |
|
| 23 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 24 |
visionai "cloud.google.com/go/visionai/apiv1" |
| 25 |
visionaipb "cloud.google.com/go/visionai/apiv1/visionaipb" |
| 26 |
"google.golang.org/api/iterator" |
| 27 |
) |
| 28 |
|
| 29 |
func ExampleNewStreamingClient() { |
| 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 := visionai.NewStreamingClient(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 ExampleNewStreamingRESTClient() { |
| 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 := visionai.NewStreamingRESTClient(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 ExampleStreamingClient_AcquireLease() { |
| 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 := visionai.NewStreamingClient(ctx) |
| 71 |
if err != nil { |
| 72 |
// TODO: Handle error. |
| 73 |
} |
| 74 |
defer c.Close() |
| 75 |
|
| 76 |
req := &visionaipb.AcquireLeaseRequest{ |
| 77 |
// TODO: Fill request struct fields. |
| 78 |
// See https://pkg.go.dev/cloud.google.com/go/visionai/apiv1/visionaipb#AcquireLeaseRequest. |
| 79 |
} |
| 80 |
resp, err := c.AcquireLease(ctx, req) |
| 81 |
if err != nil { |
| 82 |
// TODO: Handle error. |
| 83 |
} |
| 84 |
// TODO: Use resp. |
| 85 |
_ = resp |
| 86 |
} |
| 87 |
|
| 88 |
func ExampleStreamingClient_ReceiveEvents() { |
| 89 |
ctx := context.Background() |
| 90 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 91 |
// It will require modifications to work: |
| 92 |
// - It may require correct/in-range values for request initialization. |
| 93 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 94 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 95 |
c, err := visionai.NewStreamingClient(ctx) |
| 96 |
if err != nil { |
| 97 |
// TODO: Handle error. |
| 98 |
} |
| 99 |
defer c.Close() |
| 100 |
stream, err := c.ReceiveEvents(ctx) |
| 101 |
if err != nil { |
| 102 |
// TODO: Handle error. |
| 103 |
} |
| 104 |
go func() { |
| 105 |
reqs := []*visionaipb.ReceiveEventsRequest{ |
| 106 |
// TODO: Create requests. |
| 107 |
} |
| 108 |
for _, req := range reqs { |
| 109 |
if err := stream.Send(req); err != nil { |
| 110 |
// TODO: Handle error. |
| 111 |
} |
| 112 |
} |
| 113 |
stream.CloseSend() |
| 114 |
}() |
| 115 |
for { |
| 116 |
resp, err := stream.Recv() |
| 117 |
if err == io.EOF { |
| 118 |
break |
| 119 |
} |
| 120 |
if err != nil { |
| 121 |
// TODO: handle error. |
| 122 |
} |
| 123 |
// TODO: Use resp. |
| 124 |
_ = resp |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
func ExampleStreamingClient_ReceivePackets() { |
| 129 |
ctx := context.Background() |
| 130 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 131 |
// It will require modifications to work: |
| 132 |
// - It may require correct/in-range values for request initialization. |
| 133 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 134 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 135 |
c, err := visionai.NewStreamingClient(ctx) |
| 136 |
if err != nil { |
| 137 |
// TODO: Handle error. |
| 138 |
} |
| 139 |
defer c.Close() |
| 140 |
stream, err := c.ReceivePackets(ctx) |
| 141 |
if err != nil { |
| 142 |
// TODO: Handle error. |
| 143 |
} |
| 144 |
go func() { |
| 145 |
reqs := []*visionaipb.ReceivePacketsRequest{ |
| 146 |
// TODO: Create requests. |
| 147 |
} |
| 148 |
for _, req := range reqs { |
| 149 |
if err := stream.Send(req); err != nil { |
| 150 |
// TODO: Handle error. |
| 151 |
} |
| 152 |
} |
| 153 |
stream.CloseSend() |
| 154 |
}() |
| 155 |
for { |
| 156 |
resp, err := stream.Recv() |
| 157 |
if err == io.EOF { |
| 158 |
break |
| 159 |
} |
| 160 |
if err != nil { |
| 161 |
// TODO: handle error. |
| 162 |
} |
| 163 |
// TODO: Use resp. |
| 164 |
_ = resp |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
func ExampleStreamingClient_ReleaseLease() { |
| 169 |
ctx := context.Background() |
| 170 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 171 |
// It will require modifications to work: |
| 172 |
// - It may require correct/in-range values for request initialization. |
| 173 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 174 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 175 |
c, err := visionai.NewStreamingClient(ctx) |
| 176 |
if err != nil { |
| 177 |
// TODO: Handle error. |
| 178 |
} |
| 179 |
defer c.Close() |
| 180 |
|
| 181 |
req := &visionaipb.ReleaseLeaseRequest{ |
| 182 |
// TODO: Fill request struct fields. |
| 183 |
// See https://pkg.go.dev/cloud.google.com/go/visionai/apiv1/visionaipb#ReleaseLeaseRequest. |
| 184 |
} |
| 185 |
resp, err := c.ReleaseLease(ctx, req) |
| 186 |
if err != nil { |
| 187 |
// TODO: Handle error. |
| 188 |
} |
| 189 |
// TODO: Use resp. |
| 190 |
_ = resp |
| 191 |
} |
| 192 |
|
| 193 |
func ExampleStreamingClient_RenewLease() { |
| 194 |
ctx := context.Background() |
| 195 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 196 |
// It will require modifications to work: |
| 197 |
// - It may require correct/in-range values for request initialization. |
| 198 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 199 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 200 |
c, err := visionai.NewStreamingClient(ctx) |
| 201 |
if err != nil { |
| 202 |
// TODO: Handle error. |
| 203 |
} |
| 204 |
defer c.Close() |
| 205 |
|
| 206 |
req := &visionaipb.RenewLeaseRequest{ |
| 207 |
// TODO: Fill request struct fields. |
| 208 |
// See https://pkg.go.dev/cloud.google.com/go/visionai/apiv1/visionaipb#RenewLeaseRequest. |
| 209 |
} |
| 210 |
resp, err := c.RenewLease(ctx, req) |
| 211 |
if err != nil { |
| 212 |
// TODO: Handle error. |
| 213 |
} |
| 214 |
// TODO: Use resp. |
| 215 |
_ = resp |
| 216 |
} |
| 217 |
|
| 218 |
func ExampleStreamingClient_SendPackets() { |
| 219 |
ctx := context.Background() |
| 220 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 221 |
// It will require modifications to work: |
| 222 |
// - It may require correct/in-range values for request initialization. |
| 223 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 224 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 225 |
c, err := visionai.NewStreamingClient(ctx) |
| 226 |
if err != nil { |
| 227 |
// TODO: Handle error. |
| 228 |
} |
| 229 |
defer c.Close() |
| 230 |
stream, err := c.SendPackets(ctx) |
| 231 |
if err != nil { |
| 232 |
// TODO: Handle error. |
| 233 |
} |
| 234 |
go func() { |
| 235 |
reqs := []*visionaipb.SendPacketsRequest{ |
| 236 |
// TODO: Create requests. |
| 237 |
} |
| 238 |
for _, req := range reqs { |
| 239 |
if err := stream.Send(req); err != nil { |
| 240 |
// TODO: Handle error. |
| 241 |
} |
| 242 |
} |
| 243 |
stream.CloseSend() |
| 244 |
}() |
| 245 |
for { |
| 246 |
resp, err := stream.Recv() |
| 247 |
if err == io.EOF { |
| 248 |
break |
| 249 |
} |
| 250 |
if err != nil { |
| 251 |
// TODO: handle error. |
| 252 |
} |
| 253 |
// TODO: Use resp. |
| 254 |
_ = resp |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
func ExampleStreamingClient_CancelOperation() { |
| 259 |
ctx := context.Background() |
| 260 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 261 |
// It will require modifications to work: |
| 262 |
// - It may require correct/in-range values for request initialization. |
| 263 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 264 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 265 |
c, err := visionai.NewStreamingClient(ctx) |
| 266 |
if err != nil { |
| 267 |
// TODO: Handle error. |
| 268 |
} |
| 269 |
defer c.Close() |
| 270 |
|
| 271 |
req := &longrunningpb.CancelOperationRequest{ |
| 272 |
// TODO: Fill request struct fields. |
| 273 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. |
| 274 |
} |
| 275 |
err = c.CancelOperation(ctx, req) |
| 276 |
if err != nil { |
| 277 |
// TODO: Handle error. |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
func ExampleStreamingClient_DeleteOperation() { |
| 282 |
ctx := context.Background() |
| 283 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 284 |
// It will require modifications to work: |
| 285 |
// - It may require correct/in-range values for request initialization. |
| 286 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 287 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 288 |
c, err := visionai.NewStreamingClient(ctx) |
| 289 |
if err != nil { |
| 290 |
// TODO: Handle error. |
| 291 |
} |
| 292 |
defer c.Close() |
| 293 |
|
| 294 |
req := &longrunningpb.DeleteOperationRequest{ |
| 295 |
// TODO: Fill request struct fields. |
| 296 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. |
| 297 |
} |
| 298 |
err = c.DeleteOperation(ctx, req) |
| 299 |
if err != nil { |
| 300 |
// TODO: Handle error. |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
func ExampleStreamingClient_GetOperation() { |
| 305 |
ctx := context.Background() |
| 306 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 307 |
// It will require modifications to work: |
| 308 |
// - It may require correct/in-range values for request initialization. |
| 309 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 310 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 311 |
c, err := visionai.NewStreamingClient(ctx) |
| 312 |
if err != nil { |
| 313 |
// TODO: Handle error. |
| 314 |
} |
| 315 |
defer c.Close() |
| 316 |
|
| 317 |
req := &longrunningpb.GetOperationRequest{ |
| 318 |
// TODO: Fill request struct fields. |
| 319 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. |
| 320 |
} |
| 321 |
resp, err := c.GetOperation(ctx, req) |
| 322 |
if err != nil { |
| 323 |
// TODO: Handle error. |
| 324 |
} |
| 325 |
// TODO: Use resp. |
| 326 |
_ = resp |
| 327 |
} |
| 328 |
|
| 329 |
func ExampleStreamingClient_ListOperations() { |
| 330 |
ctx := context.Background() |
| 331 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 332 |
// It will require modifications to work: |
| 333 |
// - It may require correct/in-range values for request initialization. |
| 334 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 335 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 336 |
c, err := visionai.NewStreamingClient(ctx) |
| 337 |
if err != nil { |
| 338 |
// TODO: Handle error. |
| 339 |
} |
| 340 |
defer c.Close() |
| 341 |
|
| 342 |
req := &longrunningpb.ListOperationsRequest{ |
| 343 |
// TODO: Fill request struct fields. |
| 344 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. |
| 345 |
} |
| 346 |
it := c.ListOperations(ctx, req) |
| 347 |
for { |
| 348 |
resp, err := it.Next() |
| 349 |
if err == iterator.Done { |
| 350 |
break |
| 351 |
} |
| 352 |
if err != nil { |
| 353 |
// TODO: Handle error. |
| 354 |
} |
| 355 |
// TODO: Use resp. |
| 356 |
_ = resp |
| 357 |
|
| 358 |
// If you need to access the underlying RPC response, |
| 359 |
// you can do so by casting the `Response` as below. |
| 360 |
// Otherwise, remove this line. Only populated after |
| 361 |
// first call to Next(). Not safe for concurrent access. |
| 362 |
_ = it.Response.(*longrunningpb.ListOperationsResponse) |
| 363 |
} |
| 364 |
} |