cloud.google.com/go/aiplatform@v1.106.0/apiv1/schedule_client_example_test.go (about) 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 aiplatform_test 18 19 import ( 20 "context" 21 22 aiplatform "cloud.google.com/go/aiplatform/apiv1" 23 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 24 iampb "cloud.google.com/go/iam/apiv1/iampb" 25 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 26 "google.golang.org/api/iterator" 27 locationpb "google.golang.org/genproto/googleapis/cloud/location" 28 ) 29 30 func ExampleNewScheduleClient() { 31 ctx := context.Background() 32 // This snippet has been automatically generated and should be regarded as a code template only. 33 // It will require modifications to work: 34 // - It may require correct/in-range values for request initialization. 35 // - It may require specifying regional endpoints when creating the service client as shown in: 36 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 37 c, err := aiplatform.NewScheduleClient(ctx) 38 if err != nil { 39 // TODO: Handle error. 40 } 41 defer c.Close() 42 43 // TODO: Use client. 44 _ = c 45 } 46 47 func ExampleScheduleClient_CreateSchedule() { 48 ctx := context.Background() 49 // This snippet has been automatically generated and should be regarded as a code template only. 50 // It will require modifications to work: 51 // - It may require correct/in-range values for request initialization. 52 // - It may require specifying regional endpoints when creating the service client as shown in: 53 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 54 c, err := aiplatform.NewScheduleClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.CreateScheduleRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateScheduleRequest. 63 } 64 resp, err := c.CreateSchedule(ctx, req) 65 if err != nil { 66 // TODO: Handle error. 67 } 68 // TODO: Use resp. 69 _ = resp 70 } 71 72 func ExampleScheduleClient_DeleteSchedule() { 73 ctx := context.Background() 74 // This snippet has been automatically generated and should be regarded as a code template only. 75 // It will require modifications to work: 76 // - It may require correct/in-range values for request initialization. 77 // - It may require specifying regional endpoints when creating the service client as shown in: 78 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 79 c, err := aiplatform.NewScheduleClient(ctx) 80 if err != nil { 81 // TODO: Handle error. 82 } 83 defer c.Close() 84 85 req := &aiplatformpb.DeleteScheduleRequest{ 86 // TODO: Fill request struct fields. 87 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeleteScheduleRequest. 88 } 89 op, err := c.DeleteSchedule(ctx, req) 90 if err != nil { 91 // TODO: Handle error. 92 } 93 94 err = op.Wait(ctx) 95 if err != nil { 96 // TODO: Handle error. 97 } 98 } 99 100 func ExampleScheduleClient_GetSchedule() { 101 ctx := context.Background() 102 // This snippet has been automatically generated and should be regarded as a code template only. 103 // It will require modifications to work: 104 // - It may require correct/in-range values for request initialization. 105 // - It may require specifying regional endpoints when creating the service client as shown in: 106 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 107 c, err := aiplatform.NewScheduleClient(ctx) 108 if err != nil { 109 // TODO: Handle error. 110 } 111 defer c.Close() 112 113 req := &aiplatformpb.GetScheduleRequest{ 114 // TODO: Fill request struct fields. 115 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetScheduleRequest. 116 } 117 resp, err := c.GetSchedule(ctx, req) 118 if err != nil { 119 // TODO: Handle error. 120 } 121 // TODO: Use resp. 122 _ = resp 123 } 124 125 func ExampleScheduleClient_ListSchedules() { 126 ctx := context.Background() 127 // This snippet has been automatically generated and should be regarded as a code template only. 128 // It will require modifications to work: 129 // - It may require correct/in-range values for request initialization. 130 // - It may require specifying regional endpoints when creating the service client as shown in: 131 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 132 c, err := aiplatform.NewScheduleClient(ctx) 133 if err != nil { 134 // TODO: Handle error. 135 } 136 defer c.Close() 137 138 req := &aiplatformpb.ListSchedulesRequest{ 139 // TODO: Fill request struct fields. 140 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListSchedulesRequest. 141 } 142 it := c.ListSchedules(ctx, req) 143 for { 144 resp, err := it.Next() 145 if err == iterator.Done { 146 break 147 } 148 if err != nil { 149 // TODO: Handle error. 150 } 151 // TODO: Use resp. 152 _ = resp 153 154 // If you need to access the underlying RPC response, 155 // you can do so by casting the `Response` as below. 156 // Otherwise, remove this line. Only populated after 157 // first call to Next(). Not safe for concurrent access. 158 _ = it.Response.(*aiplatformpb.ListSchedulesResponse) 159 } 160 } 161 162 func ExampleScheduleClient_PauseSchedule() { 163 ctx := context.Background() 164 // This snippet has been automatically generated and should be regarded as a code template only. 165 // It will require modifications to work: 166 // - It may require correct/in-range values for request initialization. 167 // - It may require specifying regional endpoints when creating the service client as shown in: 168 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 169 c, err := aiplatform.NewScheduleClient(ctx) 170 if err != nil { 171 // TODO: Handle error. 172 } 173 defer c.Close() 174 175 req := &aiplatformpb.PauseScheduleRequest{ 176 // TODO: Fill request struct fields. 177 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#PauseScheduleRequest. 178 } 179 err = c.PauseSchedule(ctx, req) 180 if err != nil { 181 // TODO: Handle error. 182 } 183 } 184 185 func ExampleScheduleClient_ResumeSchedule() { 186 ctx := context.Background() 187 // This snippet has been automatically generated and should be regarded as a code template only. 188 // It will require modifications to work: 189 // - It may require correct/in-range values for request initialization. 190 // - It may require specifying regional endpoints when creating the service client as shown in: 191 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 192 c, err := aiplatform.NewScheduleClient(ctx) 193 if err != nil { 194 // TODO: Handle error. 195 } 196 defer c.Close() 197 198 req := &aiplatformpb.ResumeScheduleRequest{ 199 // TODO: Fill request struct fields. 200 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ResumeScheduleRequest. 201 } 202 err = c.ResumeSchedule(ctx, req) 203 if err != nil { 204 // TODO: Handle error. 205 } 206 } 207 208 func ExampleScheduleClient_UpdateSchedule() { 209 ctx := context.Background() 210 // This snippet has been automatically generated and should be regarded as a code template only. 211 // It will require modifications to work: 212 // - It may require correct/in-range values for request initialization. 213 // - It may require specifying regional endpoints when creating the service client as shown in: 214 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 215 c, err := aiplatform.NewScheduleClient(ctx) 216 if err != nil { 217 // TODO: Handle error. 218 } 219 defer c.Close() 220 221 req := &aiplatformpb.UpdateScheduleRequest{ 222 // TODO: Fill request struct fields. 223 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateScheduleRequest. 224 } 225 resp, err := c.UpdateSchedule(ctx, req) 226 if err != nil { 227 // TODO: Handle error. 228 } 229 // TODO: Use resp. 230 _ = resp 231 } 232 233 func ExampleScheduleClient_GetLocation() { 234 ctx := context.Background() 235 // This snippet has been automatically generated and should be regarded as a code template only. 236 // It will require modifications to work: 237 // - It may require correct/in-range values for request initialization. 238 // - It may require specifying regional endpoints when creating the service client as shown in: 239 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 240 c, err := aiplatform.NewScheduleClient(ctx) 241 if err != nil { 242 // TODO: Handle error. 243 } 244 defer c.Close() 245 246 req := &locationpb.GetLocationRequest{ 247 // TODO: Fill request struct fields. 248 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 249 } 250 resp, err := c.GetLocation(ctx, req) 251 if err != nil { 252 // TODO: Handle error. 253 } 254 // TODO: Use resp. 255 _ = resp 256 } 257 258 func ExampleScheduleClient_ListLocations() { 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 := aiplatform.NewScheduleClient(ctx) 266 if err != nil { 267 // TODO: Handle error. 268 } 269 defer c.Close() 270 271 req := &locationpb.ListLocationsRequest{ 272 // TODO: Fill request struct fields. 273 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 274 } 275 it := c.ListLocations(ctx, req) 276 for { 277 resp, err := it.Next() 278 if err == iterator.Done { 279 break 280 } 281 if err != nil { 282 // TODO: Handle error. 283 } 284 // TODO: Use resp. 285 _ = resp 286 287 // If you need to access the underlying RPC response, 288 // you can do so by casting the `Response` as below. 289 // Otherwise, remove this line. Only populated after 290 // first call to Next(). Not safe for concurrent access. 291 _ = it.Response.(*locationpb.ListLocationsResponse) 292 } 293 } 294 295 func ExampleScheduleClient_GetIamPolicy() { 296 ctx := context.Background() 297 // This snippet has been automatically generated and should be regarded as a code template only. 298 // It will require modifications to work: 299 // - It may require correct/in-range values for request initialization. 300 // - It may require specifying regional endpoints when creating the service client as shown in: 301 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 302 c, err := aiplatform.NewScheduleClient(ctx) 303 if err != nil { 304 // TODO: Handle error. 305 } 306 defer c.Close() 307 308 req := &iampb.GetIamPolicyRequest{ 309 // TODO: Fill request struct fields. 310 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 311 } 312 resp, err := c.GetIamPolicy(ctx, req) 313 if err != nil { 314 // TODO: Handle error. 315 } 316 // TODO: Use resp. 317 _ = resp 318 } 319 320 func ExampleScheduleClient_SetIamPolicy() { 321 ctx := context.Background() 322 // This snippet has been automatically generated and should be regarded as a code template only. 323 // It will require modifications to work: 324 // - It may require correct/in-range values for request initialization. 325 // - It may require specifying regional endpoints when creating the service client as shown in: 326 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 327 c, err := aiplatform.NewScheduleClient(ctx) 328 if err != nil { 329 // TODO: Handle error. 330 } 331 defer c.Close() 332 333 req := &iampb.SetIamPolicyRequest{ 334 // TODO: Fill request struct fields. 335 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 336 } 337 resp, err := c.SetIamPolicy(ctx, req) 338 if err != nil { 339 // TODO: Handle error. 340 } 341 // TODO: Use resp. 342 _ = resp 343 } 344 345 func ExampleScheduleClient_TestIamPermissions() { 346 ctx := context.Background() 347 // This snippet has been automatically generated and should be regarded as a code template only. 348 // It will require modifications to work: 349 // - It may require correct/in-range values for request initialization. 350 // - It may require specifying regional endpoints when creating the service client as shown in: 351 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 352 c, err := aiplatform.NewScheduleClient(ctx) 353 if err != nil { 354 // TODO: Handle error. 355 } 356 defer c.Close() 357 358 req := &iampb.TestIamPermissionsRequest{ 359 // TODO: Fill request struct fields. 360 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 361 } 362 resp, err := c.TestIamPermissions(ctx, req) 363 if err != nil { 364 // TODO: Handle error. 365 } 366 // TODO: Use resp. 367 _ = resp 368 } 369 370 func ExampleScheduleClient_CancelOperation() { 371 ctx := context.Background() 372 // This snippet has been automatically generated and should be regarded as a code template only. 373 // It will require modifications to work: 374 // - It may require correct/in-range values for request initialization. 375 // - It may require specifying regional endpoints when creating the service client as shown in: 376 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 377 c, err := aiplatform.NewScheduleClient(ctx) 378 if err != nil { 379 // TODO: Handle error. 380 } 381 defer c.Close() 382 383 req := &longrunningpb.CancelOperationRequest{ 384 // TODO: Fill request struct fields. 385 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 386 } 387 err = c.CancelOperation(ctx, req) 388 if err != nil { 389 // TODO: Handle error. 390 } 391 } 392 393 func ExampleScheduleClient_DeleteOperation() { 394 ctx := context.Background() 395 // This snippet has been automatically generated and should be regarded as a code template only. 396 // It will require modifications to work: 397 // - It may require correct/in-range values for request initialization. 398 // - It may require specifying regional endpoints when creating the service client as shown in: 399 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 400 c, err := aiplatform.NewScheduleClient(ctx) 401 if err != nil { 402 // TODO: Handle error. 403 } 404 defer c.Close() 405 406 req := &longrunningpb.DeleteOperationRequest{ 407 // TODO: Fill request struct fields. 408 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 409 } 410 err = c.DeleteOperation(ctx, req) 411 if err != nil { 412 // TODO: Handle error. 413 } 414 } 415 416 func ExampleScheduleClient_GetOperation() { 417 ctx := context.Background() 418 // This snippet has been automatically generated and should be regarded as a code template only. 419 // It will require modifications to work: 420 // - It may require correct/in-range values for request initialization. 421 // - It may require specifying regional endpoints when creating the service client as shown in: 422 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 423 c, err := aiplatform.NewScheduleClient(ctx) 424 if err != nil { 425 // TODO: Handle error. 426 } 427 defer c.Close() 428 429 req := &longrunningpb.GetOperationRequest{ 430 // TODO: Fill request struct fields. 431 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 432 } 433 resp, err := c.GetOperation(ctx, req) 434 if err != nil { 435 // TODO: Handle error. 436 } 437 // TODO: Use resp. 438 _ = resp 439 } 440 441 func ExampleScheduleClient_ListOperations() { 442 ctx := context.Background() 443 // This snippet has been automatically generated and should be regarded as a code template only. 444 // It will require modifications to work: 445 // - It may require correct/in-range values for request initialization. 446 // - It may require specifying regional endpoints when creating the service client as shown in: 447 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 448 c, err := aiplatform.NewScheduleClient(ctx) 449 if err != nil { 450 // TODO: Handle error. 451 } 452 defer c.Close() 453 454 req := &longrunningpb.ListOperationsRequest{ 455 // TODO: Fill request struct fields. 456 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 457 } 458 it := c.ListOperations(ctx, req) 459 for { 460 resp, err := it.Next() 461 if err == iterator.Done { 462 break 463 } 464 if err != nil { 465 // TODO: Handle error. 466 } 467 // TODO: Use resp. 468 _ = resp 469 470 // If you need to access the underlying RPC response, 471 // you can do so by casting the `Response` as below. 472 // Otherwise, remove this line. Only populated after 473 // first call to Next(). Not safe for concurrent access. 474 _ = it.Response.(*longrunningpb.ListOperationsResponse) 475 } 476 } 477 478 func ExampleScheduleClient_WaitOperation() { 479 ctx := context.Background() 480 // This snippet has been automatically generated and should be regarded as a code template only. 481 // It will require modifications to work: 482 // - It may require correct/in-range values for request initialization. 483 // - It may require specifying regional endpoints when creating the service client as shown in: 484 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 485 c, err := aiplatform.NewScheduleClient(ctx) 486 if err != nil { 487 // TODO: Handle error. 488 } 489 defer c.Close() 490 491 req := &longrunningpb.WaitOperationRequest{ 492 // TODO: Fill request struct fields. 493 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 494 } 495 resp, err := c.WaitOperation(ctx, req) 496 if err != nil { 497 // TODO: Handle error. 498 } 499 // TODO: Use resp. 500 _ = resp 501 }