(route string, do func(repo RepoConfig, r io.Reader), repos ...RepoConfig)
| 26 | } |
| 27 | |
| 28 | func DownloadUrlFromRepos(route string, do func(repo RepoConfig, r io.Reader), repos ...RepoConfig) bool { |
| 29 | |
| 30 | repoSet := map[string]bool{} |
| 31 | |
| 32 | for _, repo := range repos { |
| 33 | |
| 34 | if repo.Url == "" { |
| 35 | continue |
| 36 | } |
| 37 | if repoSet[repo.Url] { |
| 38 | continue |
| 39 | } |
| 40 | repoSet[repo.Url] = true |
| 41 | |
| 42 | url := fmt.Sprintf("%s/%s", strings.TrimRight(repo.Url, "/"), strings.TrimLeft(route, "/")) |
| 43 | req, err := http.NewRequest("GET", url, nil) |
| 44 | if err != nil { |
| 45 | logs.Warn(err) |
| 46 | return false |
| 47 | } |
| 48 | |
| 49 | if repo.Username+repo.Password != "" { |
| 50 | req.SetBasicAuth(repo.Username, repo.Password) |
| 51 | } |
| 52 | |
| 53 | resp, err := HttpDownloadClient.Do(req) |
| 54 | if err != nil { |
| 55 | logs.Warn(err) |
| 56 | continue |
| 57 | } |
| 58 | |
| 59 | if resp.StatusCode != 200 { |
| 60 | logs.Warnf("%d %s", resp.StatusCode, url) |
| 61 | io.Copy(io.Discard, resp.Body) |
| 62 | resp.Body.Close() |
| 63 | } else { |
| 64 | logs.Debugf("%d %s", resp.StatusCode, url) |
| 65 | do(repo, resp.Body) |
| 66 | resp.Body.Close() |
| 67 | return true |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | return false |
| 72 | } |
no test coverage detected