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 longrunning_test 18 19 import ( 20 "context" 21 22 longrunning "cloud.google.com/go/longrunning/autogen" 23 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 24 "google.golang.org/api/iterator" 25 ) 26 27 func ExampleNewOperationsClient() { 28 ctx := context.Background() 29 // This snippet has been automatically generated and should be regarded as a code template only. 30 // It will require modifications to work: 31 // - It may require correct/in-range values for request initialization. 32 // - It may require specifying regional endpoints when creating the service client as shown in: 33 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 34 c, err := longrunning.NewOperationsClient(ctx) 35 if err != nil { 36 // TODO: Handle error. 37 } 38 defer c.Close() 39 40 // TODO: Use client. 41 _ = c 42 } 43 44 func ExampleNewOperationsRESTClient() { 45 ctx := context.Background() 46 // This snippet has been automatically generated and should be regarded as a code template only. 47 // It will require modifications to work: 48 // - It may require correct/in-range values for request initialization. 49 // - It may require specifying regional endpoints when creating the service client as shown in: 50 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 51 c, err := longrunning.NewOperationsRESTClient(ctx) 52 if err != nil { 53 // TODO: Handle error. 54 } 55 defer c.Close() 56 57 // TODO: Use client. 58 _ = c 59 } 60 61 func ExampleOperationsClient_CancelOperation() { 62 ctx := context.Background() 63 // This snippet has been automatically generated and should be regarded as a code template only. 64 // It will require modifications to work: 65 // - It may require correct/in-range values for request initialization. 66 // - It may require specifying regional endpoints when creating the service client as shown in: 67 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 68 c, err := longrunning.NewOperationsClient(ctx) 69 if err != nil { 70 // TODO: Handle error. 71 } 72 defer c.Close() 73 74 req := &longrunningpb.CancelOperationRequest{ 75 // TODO: Fill request struct fields. 76 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 77 } 78 err = c.CancelOperation(ctx, req) 79 if err != nil { 80 // TODO: Handle error. 81 } 82 } 83 84 func ExampleOperationsClient_DeleteOperation() { 85 ctx := context.Background() 86 // This snippet has been automatically generated and should be regarded as a code template only. 87 // It will require modifications to work: 88 // - It may require correct/in-range values for request initialization. 89 // - It may require specifying regional endpoints when creating the service client as shown in: 90 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 91 c, err := longrunning.NewOperationsClient(ctx) 92 if err != nil { 93 // TODO: Handle error. 94 } 95 defer c.Close() 96 97 req := &longrunningpb.DeleteOperationRequest{ 98 // TODO: Fill request struct fields. 99 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 100 } 101 err = c.DeleteOperation(ctx, req) 102 if err != nil { 103 // TODO: Handle error. 104 } 105 } 106 107 func ExampleOperationsClient_GetOperation() { 108 ctx := context.Background() 109 // This snippet has been automatically generated and should be regarded as a code template only. 110 // It will require modifications to work: 111 // - It may require correct/in-range values for request initialization. 112 // - It may require specifying regional endpoints when creating the service client as shown in: 113 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 114 c, err := longrunning.NewOperationsClient(ctx) 115 if err != nil { 116 // TODO: Handle error. 117 } 118 defer c.Close() 119 120 req := &longrunningpb.GetOperationRequest{ 121 // TODO: Fill request struct fields. 122 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 123 } 124 resp, err := c.GetOperation(ctx, req) 125 if err != nil { 126 // TODO: Handle error. 127 } 128 // TODO: Use resp. 129 _ = resp 130 } 131 132 func ExampleOperationsClient_ListOperations() { 133 ctx := context.Background() 134 // This snippet has been automatically generated and should be regarded as a code template only. 135 // It will require modifications to work: 136 // - It may require correct/in-range values for request initialization. 137 // - It may require specifying regional endpoints when creating the service client as shown in: 138 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 139 c, err := longrunning.NewOperationsClient(ctx) 140 if err != nil { 141 // TODO: Handle error. 142 } 143 defer c.Close() 144 145 req := &longrunningpb.ListOperationsRequest{ 146 // TODO: Fill request struct fields. 147 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 148 } 149 it := c.ListOperations(ctx, req) 150 for { 151 resp, err := it.Next() 152 if err == iterator.Done { 153 break 154 } 155 if err != nil { 156 // TODO: Handle error. 157 } 158 // TODO: Use resp. 159 _ = resp 160 161 // If you need to access the underlying RPC response, 162 // you can do so by casting the `Response` as below. 163 // Otherwise, remove this line. Only populated after 164 // first call to Next(). Not safe for concurrent access. 165 _ = it.Response.(*longrunningpb.ListOperationsResponse) 166 } 167 } 168 169 func ExampleOperationsClient_WaitOperation() { 170 ctx := context.Background() 171 // This snippet has been automatically generated and should be regarded as a code template only. 172 // It will require modifications to work: 173 // - It may require correct/in-range values for request initialization. 174 // - It may require specifying regional endpoints when creating the service client as shown in: 175 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 176 c, err := longrunning.NewOperationsClient(ctx) 177 if err != nil { 178 // TODO: Handle error. 179 } 180 defer c.Close() 181 182 req := &longrunningpb.WaitOperationRequest{ 183 // TODO: Fill request struct fields. 184 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 185 } 186 resp, err := c.WaitOperation(ctx, req) 187 if err != nil { 188 // TODO: Handle error. 189 } 190 // TODO: Use resp. 191 _ = resp 192 } 193