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 control 18 19 import ( 20 "context" 21 "time" 22 23 "cloud.google.com/go/longrunning" 24 controlpb "cloud.google.com/go/storage/control/apiv2/controlpb" 25 gax "github.com/googleapis/gax-go/v2" 26 "google.golang.org/api/iterator" 27 ) 28 29 // RenameFolderOperation manages a long-running operation from RenameFolder. 30 type RenameFolderOperation struct { 31 lro *longrunning.Operation 32 } 33 34 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 35 // 36 // See documentation of Poll for error-handling information. 37 func (op *RenameFolderOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*controlpb.Folder, error) { 38 var resp controlpb.Folder 39 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 40 return nil, err 41 } 42 return &resp, nil 43 } 44 45 // Poll fetches the latest state of the long-running operation. 46 // 47 // Poll also fetches the latest metadata, which can be retrieved by Metadata. 48 // 49 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 50 // the operation has completed with failure, the error is returned and op.Done will return true. 51 // If Poll succeeds and the operation has completed successfully, 52 // op.Done will return true, and the response of the operation is returned. 53 // If Poll succeeds and the operation has not completed, the returned response and error are both nil. 54 func (op *RenameFolderOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*controlpb.Folder, error) { 55 var resp controlpb.Folder 56 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 57 return nil, err 58 } 59 if !op.Done() { 60 return nil, nil 61 } 62 return &resp, nil 63 } 64 65 // Metadata returns metadata associated with the long-running operation. 66 // Metadata itself does not contact the server, but Poll does. 67 // To get the latest metadata, call this method after a successful call to Poll. 68 // If the metadata is not available, the returned metadata and error are both nil. 69 func (op *RenameFolderOperation) Metadata() (*controlpb.RenameFolderMetadata, error) { 70 var meta controlpb.RenameFolderMetadata 71 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 72 return nil, nil 73 } else if err != nil { 74 return nil, err 75 } 76 return &meta, nil 77 } 78 79 // Done reports whether the long-running operation has completed. 80 func (op *RenameFolderOperation) Done() bool { 81 return op.lro.Done() 82 } 83 84 // Name returns the name of the long-running operation. 85 // The name is assigned by the server and is unique within the service from which the operation is created. 86 func (op *RenameFolderOperation) Name() string { 87 return op.lro.Name() 88 } 89 90 // FolderIterator manages a stream of *controlpb.Folder. 91 type FolderIterator struct { 92 items []*controlpb.Folder 93 pageInfo *iterator.PageInfo 94 nextFunc func() error 95 96 // Response is the raw response for the current page. 97 // It must be cast to the RPC response type. 98 // Calling Next() or InternalFetch() updates this value. 99 Response interface{} 100 101 // InternalFetch is for use by the Google Cloud Libraries only. 102 // It is not part of the stable interface of this package. 103 // 104 // InternalFetch returns results from a single call to the underlying RPC. 105 // The number of results is no greater than pageSize. 106 // If there are no more results, nextPageToken is empty and err is nil. 107 InternalFetch func(pageSize int, pageToken string) (results []*controlpb.Folder, nextPageToken string, err error) 108 } 109 110 // PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 111 func (it *FolderIterator) PageInfo() *iterator.PageInfo { 112 return it.pageInfo 113 } 114 115 // Next returns the next result. Its second return value is iterator.Done if there are no more 116 // results. Once Next returns Done, all subsequent calls will return Done. 117 func (it *FolderIterator) Next() (*controlpb.Folder, error) { 118 var item *controlpb.Folder 119 if err := it.nextFunc(); err != nil { 120 return item, err 121 } 122 item = it.items[0] 123 it.items = it.items[1:] 124 return item, nil 125 } 126 127 func (it *FolderIterator) bufLen() int { 128 return len(it.items) 129 } 130 131 func (it *FolderIterator) takeBuf() interface{} { 132 b := it.items 133 it.items = nil 134 return b 135 } 136 137 // ManagedFolderIterator manages a stream of *controlpb.ManagedFolder. 138 type ManagedFolderIterator struct { 139 items []*controlpb.ManagedFolder 140 pageInfo *iterator.PageInfo 141 nextFunc func() error 142 143 // Response is the raw response for the current page. 144 // It must be cast to the RPC response type. 145 // Calling Next() or InternalFetch() updates this value. 146 Response interface{} 147 148 // InternalFetch is for use by the Google Cloud Libraries only. 149 // It is not part of the stable interface of this package. 150 // 151 // InternalFetch returns results from a single call to the underlying RPC. 152 // The number of results is no greater than pageSize. 153 // If there are no more results, nextPageToken is empty and err is nil. 154 InternalFetch func(pageSize int, pageToken string) (results []*controlpb.ManagedFolder, nextPageToken string, err error) 155 } 156 157 // PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 158 func (it *ManagedFolderIterator) PageInfo() *iterator.PageInfo { 159 return it.pageInfo 160 } 161 162 // Next returns the next result. Its second return value is iterator.Done if there are no more 163 // results. Once Next returns Done, all subsequent calls will return Done. 164 func (it *ManagedFolderIterator) Next() (*controlpb.ManagedFolder, error) { 165 var item *controlpb.ManagedFolder 166 if err := it.nextFunc(); err != nil { 167 return item, err 168 } 169 item = it.items[0] 170 it.items = it.items[1:] 171 return item, nil 172 } 173 174 func (it *ManagedFolderIterator) bufLen() int { 175 return len(it.items) 176 } 177 178 func (it *ManagedFolderIterator) takeBuf() interface{} { 179 b := it.items 180 it.items = nil 181 return b 182 } 183