( ctx context.Context, uri string, hash string, )
| 257 | var narInfoStatusFnCache = sync.Map{} |
| 258 | |
| 259 | func fetchNarInfoStatusFromHTTP( |
| 260 | ctx context.Context, |
| 261 | uri string, |
| 262 | hash string, |
| 263 | ) (bool, error) { |
| 264 | key := fmt.Sprintf("%s/%s", uri, hash) |
| 265 | fetch, _ := narInfoStatusFnCache.LoadOrStore(key, sync.OnceValues( |
| 266 | func() (bool, error) { |
| 267 | ctx, cancel := context.WithTimeout(ctx, 5*time.Second) |
| 268 | defer cancel() |
| 269 | url := fmt.Sprintf("%s/%s.narinfo", uri, hash) |
| 270 | req, err := http.NewRequestWithContext(ctx, http.MethodHead, url, nil) |
| 271 | if err != nil { |
| 272 | return false, err |
| 273 | } |
| 274 | res, err := http.DefaultClient.Do(req) |
| 275 | if err != nil { |
| 276 | return false, err |
| 277 | } |
| 278 | defer res.Body.Close() |
| 279 | return res.StatusCode == http.StatusOK, nil |
| 280 | }, |
| 281 | )) |
| 282 | return fetch.(func() (bool, error))() |
| 283 | } |
| 284 | |
| 285 | func fetchNarInfoStatusFromS3( |
| 286 | ctx context.Context, |
no test coverage detected