github.com/openshift-online/ocm-sdk-go@v0.1.473/webrca/v1/errors_client.go (about) 1 /* 2 Copyright (c) 2020 Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // IMPORTANT: This file has been generated automatically, refrain from modifying it manually as all 18 // your changes will be lost when the file is generated again. 19 20 package v1 // github.com/openshift-online/ocm-sdk-go/webrca/v1 21 22 import ( 23 "bufio" 24 "context" 25 "io" 26 "net/http" 27 "net/url" 28 "path" 29 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // ErrorsClient is the client of the 'errors' resource. 35 // 36 // Manages the collection of errors. 37 type ErrorsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewErrorsClient creates a new client for the 'errors' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewErrorsClient(transport http.RoundTripper, path string) *ErrorsClient { 46 return &ErrorsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // List creates a request for the 'list' method. 53 // 54 // Retrieves the list of errors. 55 func (c *ErrorsClient) List() *ErrorsListRequest { 56 return &ErrorsListRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // Error returns the target 'error' resource for the given identifier. 63 func (c *ErrorsClient) Error(id string) *ErrorClient { 64 return NewErrorClient( 65 c.transport, 66 path.Join(c.path, id), 67 ) 68 } 69 70 // ErrorsListRequest is the request for the 'list' method. 71 type ErrorsListRequest struct { 72 transport http.RoundTripper 73 path string 74 query url.Values 75 header http.Header 76 page *int 77 size *int 78 } 79 80 // Parameter adds a query parameter. 81 func (r *ErrorsListRequest) Parameter(name string, value interface{}) *ErrorsListRequest { 82 helpers.AddValue(&r.query, name, value) 83 return r 84 } 85 86 // Header adds a request header. 87 func (r *ErrorsListRequest) Header(name string, value interface{}) *ErrorsListRequest { 88 helpers.AddHeader(&r.header, name, value) 89 return r 90 } 91 92 // Impersonate wraps requests on behalf of another user. 93 // Note: Services that do not support this feature may silently ignore this call. 94 func (r *ErrorsListRequest) Impersonate(user string) *ErrorsListRequest { 95 helpers.AddImpersonationHeader(&r.header, user) 96 return r 97 } 98 99 // Page sets the value of the 'page' parameter. 100 func (r *ErrorsListRequest) Page(value int) *ErrorsListRequest { 101 r.page = &value 102 return r 103 } 104 105 // Size sets the value of the 'size' parameter. 106 func (r *ErrorsListRequest) Size(value int) *ErrorsListRequest { 107 r.size = &value 108 return r 109 } 110 111 // Send sends this request, waits for the response, and returns it. 112 // 113 // This is a potentially lengthy operation, as it requires network communication. 114 // Consider using a context and the SendContext method. 115 func (r *ErrorsListRequest) Send() (result *ErrorsListResponse, err error) { 116 return r.SendContext(context.Background()) 117 } 118 119 // SendContext sends this request, waits for the response, and returns it. 120 func (r *ErrorsListRequest) SendContext(ctx context.Context) (result *ErrorsListResponse, err error) { 121 query := helpers.CopyQuery(r.query) 122 if r.page != nil { 123 helpers.AddValue(&query, "page", *r.page) 124 } 125 if r.size != nil { 126 helpers.AddValue(&query, "size", *r.size) 127 } 128 header := helpers.CopyHeader(r.header) 129 uri := &url.URL{ 130 Path: r.path, 131 RawQuery: query.Encode(), 132 } 133 request := &http.Request{ 134 Method: "GET", 135 URL: uri, 136 Header: header, 137 } 138 if ctx != nil { 139 request = request.WithContext(ctx) 140 } 141 response, err := r.transport.RoundTrip(request) 142 if err != nil { 143 return 144 } 145 defer response.Body.Close() 146 result = &ErrorsListResponse{} 147 result.status = response.StatusCode 148 result.header = response.Header 149 reader := bufio.NewReader(response.Body) 150 _, err = reader.Peek(1) 151 if err == io.EOF { 152 err = nil 153 return 154 } 155 if result.status >= 400 { 156 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 157 if err != nil { 158 return 159 } 160 err = result.err 161 return 162 } 163 err = readErrorsListResponse(result, reader) 164 if err != nil { 165 return 166 } 167 return 168 } 169 170 // ErrorsListResponse is the response for the 'list' method. 171 type ErrorsListResponse struct { 172 status int 173 header http.Header 174 err *errors.Error 175 items *ErrorList 176 page *int 177 size *int 178 total *int 179 } 180 181 // Status returns the response status code. 182 func (r *ErrorsListResponse) Status() int { 183 if r == nil { 184 return 0 185 } 186 return r.status 187 } 188 189 // Header returns header of the response. 190 func (r *ErrorsListResponse) Header() http.Header { 191 if r == nil { 192 return nil 193 } 194 return r.header 195 } 196 197 // Error returns the response error. 198 func (r *ErrorsListResponse) Error() *errors.Error { 199 if r == nil { 200 return nil 201 } 202 return r.err 203 } 204 205 // Items returns the value of the 'items' parameter. 206 func (r *ErrorsListResponse) Items() *ErrorList { 207 if r == nil { 208 return nil 209 } 210 return r.items 211 } 212 213 // GetItems returns the value of the 'items' parameter and 214 // a flag indicating if the parameter has a value. 215 func (r *ErrorsListResponse) GetItems() (value *ErrorList, ok bool) { 216 ok = r != nil && r.items != nil 217 if ok { 218 value = r.items 219 } 220 return 221 } 222 223 // Page returns the value of the 'page' parameter. 224 func (r *ErrorsListResponse) Page() int { 225 if r != nil && r.page != nil { 226 return *r.page 227 } 228 return 0 229 } 230 231 // GetPage returns the value of the 'page' parameter and 232 // a flag indicating if the parameter has a value. 233 func (r *ErrorsListResponse) GetPage() (value int, ok bool) { 234 ok = r != nil && r.page != nil 235 if ok { 236 value = *r.page 237 } 238 return 239 } 240 241 // Size returns the value of the 'size' parameter. 242 func (r *ErrorsListResponse) Size() int { 243 if r != nil && r.size != nil { 244 return *r.size 245 } 246 return 0 247 } 248 249 // GetSize returns the value of the 'size' parameter and 250 // a flag indicating if the parameter has a value. 251 func (r *ErrorsListResponse) GetSize() (value int, ok bool) { 252 ok = r != nil && r.size != nil 253 if ok { 254 value = *r.size 255 } 256 return 257 } 258 259 // Total returns the value of the 'total' parameter. 260 func (r *ErrorsListResponse) Total() int { 261 if r != nil && r.total != nil { 262 return *r.total 263 } 264 return 0 265 } 266 267 // GetTotal returns the value of the 'total' parameter and 268 // a flag indicating if the parameter has a value. 269 func (r *ErrorsListResponse) GetTotal() (value int, ok bool) { 270 ok = r != nil && r.total != nil 271 if ok { 272 value = *r.total 273 } 274 return 275 }