| 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 gkehub |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "time" |
| 22 | |
| 23 | gkehubpb "cloud.google.com/go/gkehub/apiv1beta1/gkehubpb" |
| 24 | "cloud.google.com/go/longrunning" |
| 25 | longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 26 | gax "github.com/googleapis/gax-go/v2" |
| 27 | "google.golang.org/api/iterator" |
| 28 | locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 29 | ) |
| 30 | |
| 31 | // CreateMembershipOperation manages a long-running operation from CreateMembership. |
| 32 | type CreateMembershipOperation struct { |
| 33 | lro *longrunning.Operation |
| 34 | pollPath string |
| 35 | } |
| 36 | |
| 37 | // Wait blocks until the long-running operation is completed, returning the response and any errors encountered. |
| 38 | // |
| 39 | // See documentation of Poll for error-handling information. |
| 40 | func (op *CreateMembershipOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*gkehubpb.Membership, error) { |
| 41 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 42 | var resp gkehubpb.Membership |
| 43 | if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | return &resp, nil |
| 47 | } |
| 48 | |
| 49 | // Poll fetches the latest state of the long-running operation. |
| 50 | // |
| 51 | // Poll also fetches the latest metadata, which can be retrieved by Metadata. |
| 52 | // |
| 53 | // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and |
| 54 | // the operation has completed with failure, the error is returned and op.Done will return true. |
| 55 | // If Poll succeeds and the operation has completed successfully, |
| 56 | // op.Done will return true, and the response of the operation is returned. |
| 57 | // If Poll succeeds and the operation has not completed, the returned response and error are both nil. |
| 58 | func (op *CreateMembershipOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*gkehubpb.Membership, error) { |
| 59 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 60 | var resp gkehubpb.Membership |
| 61 | if err := op.lro.Poll(ctx, &resp, opts...); err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | if !op.Done() { |
| 65 | return nil, nil |
| 66 | } |
| 67 | return &resp, nil |
| 68 | } |
| 69 | |
| 70 | // Metadata returns metadata associated with the long-running operation. |
| 71 | // Metadata itself does not contact the server, but Poll does. |
| 72 | // To get the latest metadata, call this method after a successful call to Poll. |
| 73 | // If the metadata is not available, the returned metadata and error are both nil. |
| 74 | func (op *CreateMembershipOperation) Metadata() (*gkehubpb.OperationMetadata, error) { |
| 75 | var meta gkehubpb.OperationMetadata |
| 76 | if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 77 | return nil, nil |
| 78 | } else if err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | return &meta, nil |
| 82 | } |
| 83 | |
| 84 | // Done reports whether the long-running operation has completed. |
| 85 | func (op *CreateMembershipOperation) Done() bool { |
| 86 | return op.lro.Done() |
| 87 | } |
| 88 | |
| 89 | // Name returns the name of the long-running operation. |
| 90 | // The name is assigned by the server and is unique within the service from which the operation is created. |
| 91 | func (op *CreateMembershipOperation) Name() string { |
| 92 | return op.lro.Name() |
| 93 | } |
| 94 | |
| 95 | // DeleteMembershipOperation manages a long-running operation from DeleteMembership. |
| 96 | type DeleteMembershipOperation struct { |
| 97 | lro *longrunning.Operation |
| 98 | pollPath string |
| 99 | } |
| 100 | |
| 101 | // Wait blocks until the long-running operation is completed, returning the response and any errors encountered. |
| 102 | // |
| 103 | // See documentation of Poll for error-handling information. |
| 104 | func (op *DeleteMembershipOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { |
| 105 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 106 | return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) |
| 107 | } |
| 108 | |
| 109 | // Poll fetches the latest state of the long-running operation. |
| 110 | // |
| 111 | // Poll also fetches the latest metadata, which can be retrieved by Metadata. |
| 112 | // |
| 113 | // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and |
| 114 | // the operation has completed with failure, the error is returned and op.Done will return true. |
| 115 | // If Poll succeeds and the operation has completed successfully, |
| 116 | // op.Done will return true, and the response of the operation is returned. |
| 117 | // If Poll succeeds and the operation has not completed, the returned response and error are both nil. |
| 118 | func (op *DeleteMembershipOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { |
| 119 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 120 | return op.lro.Poll(ctx, nil, opts...) |
| 121 | } |
| 122 | |
| 123 | // Metadata returns metadata associated with the long-running operation. |
| 124 | // Metadata itself does not contact the server, but Poll does. |
| 125 | // To get the latest metadata, call this method after a successful call to Poll. |
| 126 | // If the metadata is not available, the returned metadata and error are both nil. |
| 127 | func (op *DeleteMembershipOperation) Metadata() (*gkehubpb.OperationMetadata, error) { |
| 128 | var meta gkehubpb.OperationMetadata |
| 129 | if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 130 | return nil, nil |
| 131 | } else if err != nil { |
| 132 | return nil, err |
| 133 | } |
| 134 | return &meta, nil |
| 135 | } |
| 136 | |
| 137 | // Done reports whether the long-running operation has completed. |
| 138 | func (op *DeleteMembershipOperation) Done() bool { |
| 139 | return op.lro.Done() |
| 140 | } |
| 141 | |
| 142 | // Name returns the name of the long-running operation. |
| 143 | // The name is assigned by the server and is unique within the service from which the operation is created. |
| 144 | func (op *DeleteMembershipOperation) Name() string { |
| 145 | return op.lro.Name() |
| 146 | } |
| 147 | |
| 148 | // UpdateMembershipOperation manages a long-running operation from UpdateMembership. |
| 149 | type UpdateMembershipOperation struct { |
| 150 | lro *longrunning.Operation |
| 151 | pollPath string |
| 152 | } |
| 153 | |
| 154 | // Wait blocks until the long-running operation is completed, returning the response and any errors encountered. |
| 155 | // |
| 156 | // See documentation of Poll for error-handling information. |
| 157 | func (op *UpdateMembershipOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*gkehubpb.Membership, error) { |
| 158 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 159 | var resp gkehubpb.Membership |
| 160 | if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { |
| 161 | return nil, err |
| 162 | } |
| 163 | return &resp, nil |
| 164 | } |
| 165 | |
| 166 | // Poll fetches the latest state of the long-running operation. |
| 167 | // |
| 168 | // Poll also fetches the latest metadata, which can be retrieved by Metadata. |
| 169 | // |
| 170 | // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and |
| 171 | // the operation has completed with failure, the error is returned and op.Done will return true. |
| 172 | // If Poll succeeds and the operation has completed successfully, |
| 173 | // op.Done will return true, and the response of the operation is returned. |
| 174 | // If Poll succeeds and the operation has not completed, the returned response and error are both nil. |
| 175 | func (op *UpdateMembershipOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*gkehubpb.Membership, error) { |
| 176 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 177 | var resp gkehubpb.Membership |
| 178 | if err := op.lro.Poll(ctx, &resp, opts...); err != nil { |
| 179 | return nil, err |
| 180 | } |
| 181 | if !op.Done() { |
| 182 | return nil, nil |
| 183 | } |
| 184 | return &resp, nil |
| 185 | } |
| 186 | |
| 187 | // Metadata returns metadata associated with the long-running operation. |
| 188 | // Metadata itself does not contact the server, but Poll does. |
| 189 | // To get the latest metadata, call this method after a successful call to Poll. |
| 190 | // If the metadata is not available, the returned metadata and error are both nil. |
| 191 | func (op *UpdateMembershipOperation) Metadata() (*gkehubpb.OperationMetadata, error) { |
| 192 | var meta gkehubpb.OperationMetadata |
| 193 | if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 194 | return nil, nil |
| 195 | } else if err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | return &meta, nil |
| 199 | } |
| 200 | |
| 201 | // Done reports whether the long-running operation has completed. |
| 202 | func (op *UpdateMembershipOperation) Done() bool { |
| 203 | return op.lro.Done() |
| 204 | } |
| 205 | |
| 206 | // Name returns the name of the long-running operation. |
| 207 | // The name is assigned by the server and is unique within the service from which the operation is created. |
| 208 | func (op *UpdateMembershipOperation) Name() string { |
| 209 | return op.lro.Name() |
| 210 | } |
| 211 | |
| 212 | // LocationIterator manages a stream of *locationpb.Location. |
| 213 | type LocationIterator struct { |
| 214 | items []*locationpb.Location |
| 215 | pageInfo *iterator.PageInfo |
| 216 | nextFunc func() error |
| 217 | |
| 218 | // Response is the raw response for the current page. |
| 219 | // It must be cast to the RPC response type. |
| 220 | // Calling Next() or InternalFetch() updates this value. |
| 221 | Response interface{} |
| 222 | |
| 223 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 224 | // It is not part of the stable interface of this package. |
| 225 | // |
| 226 | // InternalFetch returns results from a single call to the underlying RPC. |
| 227 | // The number of results is no greater than pageSize. |
| 228 | // If there are no more results, nextPageToken is empty and err is nil. |
| 229 | InternalFetch func(pageSize int, pageToken string) (results []*locationpb.Location, nextPageToken string, err error) |
| 230 | } |
| 231 | |
| 232 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 233 | func (it *LocationIterator) PageInfo() *iterator.PageInfo { |
| 234 | return it.pageInfo |
| 235 | } |
| 236 | |
| 237 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 238 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 239 | func (it *LocationIterator) Next() (*locationpb.Location, error) { |
| 240 | var item *locationpb.Location |
| 241 | if err := it.nextFunc(); err != nil { |
| 242 | return item, err |
| 243 | } |
| 244 | item = it.items[0] |
| 245 | it.items = it.items[1:] |
| 246 | return item, nil |
| 247 | } |
| 248 | |
| 249 | func (it *LocationIterator) bufLen() int { |
| 250 | return len(it.items) |
| 251 | } |
| 252 | |
| 253 | func (it *LocationIterator) takeBuf() interface{} { |
| 254 | b := it.items |
| 255 | it.items = nil |
| 256 | return b |
| 257 | } |
| 258 | |
| 259 | // MembershipIterator manages a stream of *gkehubpb.Membership. |
| 260 | type MembershipIterator struct { |
| 261 | items []*gkehubpb.Membership |
| 262 | pageInfo *iterator.PageInfo |
| 263 | nextFunc func() error |
| 264 | |
| 265 | // Response is the raw response for the current page. |
| 266 | // It must be cast to the RPC response type. |
| 267 | // Calling Next() or InternalFetch() updates this value. |
| 268 | Response interface{} |
| 269 | |
| 270 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 271 | // It is not part of the stable interface of this package. |
| 272 | // |
| 273 | // InternalFetch returns results from a single call to the underlying RPC. |
| 274 | // The number of results is no greater than pageSize. |
| 275 | // If there are no more results, nextPageToken is empty and err is nil. |
| 276 | InternalFetch func(pageSize int, pageToken string) (results []*gkehubpb.Membership, nextPageToken string, err error) |
| 277 | } |
| 278 | |
| 279 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 280 | func (it *MembershipIterator) PageInfo() *iterator.PageInfo { |
| 281 | return it.pageInfo |
| 282 | } |
| 283 | |
| 284 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 285 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 286 | func (it *MembershipIterator) Next() (*gkehubpb.Membership, error) { |
| 287 | var item *gkehubpb.Membership |
| 288 | if err := it.nextFunc(); err != nil { |
| 289 | return item, err |
| 290 | } |
| 291 | item = it.items[0] |
| 292 | it.items = it.items[1:] |
| 293 | return item, nil |
| 294 | } |
| 295 | |
| 296 | func (it *MembershipIterator) bufLen() int { |
| 297 | return len(it.items) |
| 298 | } |
| 299 | |
| 300 | func (it *MembershipIterator) takeBuf() interface{} { |
| 301 | b := it.items |
| 302 | it.items = nil |
| 303 | return b |
| 304 | } |
| 305 | |
| 306 | // OperationIterator manages a stream of *longrunningpb.Operation. |
| 307 | type OperationIterator struct { |
| 308 | items []*longrunningpb.Operation |
| 309 | pageInfo *iterator.PageInfo |
| 310 | nextFunc func() error |
| 311 | |
| 312 | // Response is the raw response for the current page. |
| 313 | // It must be cast to the RPC response type. |
| 314 | // Calling Next() or InternalFetch() updates this value. |
| 315 | Response interface{} |
| 316 | |
| 317 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 318 | // It is not part of the stable interface of this package. |
| 319 | // |
| 320 | // InternalFetch returns results from a single call to the underlying RPC. |
| 321 | // The number of results is no greater than pageSize. |
| 322 | // If there are no more results, nextPageToken is empty and err is nil. |
| 323 | InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) |
| 324 | } |
| 325 | |
| 326 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 327 | func (it *OperationIterator) PageInfo() *iterator.PageInfo { |
| 328 | return it.pageInfo |
| 329 | } |
| 330 | |
| 331 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 332 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 333 | func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { |
| 334 | var item *longrunningpb.Operation |
| 335 | if err := it.nextFunc(); err != nil { |
| 336 | return item, err |
| 337 | } |
| 338 | item = it.items[0] |
| 339 | it.items = it.items[1:] |
| 340 | return item, nil |
| 341 | } |
| 342 | |
| 343 | func (it *OperationIterator) bufLen() int { |
| 344 | return len(it.items) |
| 345 | } |
| 346 | |
| 347 | func (it *OperationIterator) takeBuf() interface{} { |
| 348 | b := it.items |
| 349 | it.items = nil |
| 350 | return b |
| 351 | } |