updateOperations is a private method implementing the common bits for retrieving UpdateOperations an ouCache is passed in by the caller to cache any responses providing an etag. if a subsequent response provides a StatusNotModified status, the map of UpdateOprations is served from cache.
(ctx context.Context, req *http.Request, cache *uoCache)
| 191 | // an ouCache is passed in by the caller to cache any responses providing an etag. |
| 192 | // if a subsequent response provides a StatusNotModified status, the map of UpdateOprations is served from cache. |
| 193 | func (c *HTTP) updateOperations(ctx context.Context, req *http.Request, cache *uoCache) (map[string][]driver.UpdateOperation, error) { |
| 194 | if err := c.sign(ctx, req); err != nil { |
| 195 | return nil, fmt.Errorf("failed to create request: %v", err) |
| 196 | } |
| 197 | res, err := c.c.Do(req) |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | defer res.Body.Close() |
| 202 | switch res.StatusCode { |
| 203 | case http.StatusOK: |
| 204 | m := make(map[string][]driver.UpdateOperation) |
| 205 | dec := codec.GetDecoder(res.Body) |
| 206 | defer codec.PutDecoder(dec) |
| 207 | if err := dec.Decode(&m); err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | // check for etag, if exists store the value and add returned map |
| 211 | // to cache |
| 212 | if v := res.Header.Get("etag"); v != "" && !strings.HasPrefix(v, "W/") { |
| 213 | cache.Set(m, v) |
| 214 | } |
| 215 | return cache.Copy(), nil |
| 216 | case http.StatusNotModified: |
| 217 | return cache.Copy(), nil |
| 218 | default: |
| 219 | } |
| 220 | return nil, fmt.Errorf("%v: unexpected status: %s", req.URL.Path, res.Status) |
| 221 | } |
| 222 | |
| 223 | // UpdateDiff reports the diff of two update operations, identified by the |
| 224 | // provided refs. |
no test coverage detected