()
| 106 | } |
| 107 | |
| 108 | func fetch() (map[string]upstreamProvider, error) { |
| 109 | ctx, cancel := context.WithTimeout(context.Background(), fetchTimeout) |
| 110 | defer cancel() |
| 111 | |
| 112 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, sourceURL, nil) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | resp, err := http.DefaultClient.Do(req) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | defer resp.Body.Close() |
| 121 | if resp.StatusCode != http.StatusOK { |
| 122 | return nil, xerrors.Errorf("status %d", resp.StatusCode) |
| 123 | } |
| 124 | |
| 125 | var data map[string]upstreamProvider |
| 126 | if err := json.NewDecoder(io.LimitReader(resp.Body, maxBodyBytes)).Decode(&data); err != nil { |
| 127 | return nil, xerrors.Errorf("parse: %w", err) |
| 128 | } |
| 129 | return data, nil |
| 130 | } |
| 131 | |
| 132 | // convert flattens the upstream map into table-shaped rows for the configured |
| 133 | // providers. If any configured provider is absent from the upstream payload, |
no test coverage detected