package distro import ( "bufio" "net/http" "regexp" "strings" "sync" ) type Arch struct{} func (d Arch) GetName() string { return "arch" } func (d Arch) GetRepos() []string { return []string{DefaultRepo} } func (d Arch) FetchMirrors(repos []string, repoMirrors chan<- RepoMirror, done *sync.WaitGroup) { defer done.Done() // re := regexp.MustCompile(`^#*\s*Server\s*=\s*(\S+)\$repo/os/\$arch`) re := regexp.MustCompile(`^#*\s*Server\s*=\s*(\S+?)[^/]+/os/[^/]+/?\s*$`) resp, err := http.Get("https://archlinux.org/mirrorlist/all/") if err != nil { return } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { scanner := bufio.NewScanner(resp.Body) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) m := re.FindSubmatch([]byte(line)) if len(m) > 1 { repoMirrors <- RepoMirror{d.GetName(), DefaultRepo, string(m[1])} } } } }