package distro import ( "strings" "sync" "github.com/gocolly/colly" ) type Alpine struct{} func (d Alpine) GetName() string { return "alpine" } func (d Alpine) GetRepos() []string { return []string{DefaultRepo} } func (d Alpine) FetchMirrors(repos []string, repoMirrors chan<- RepoMirror, done *sync.WaitGroup) { defer done.Done() c := colly.NewCollector( colly.AllowedDomains("mirrors.alpinelinux.org"), ) c.OnHTML("div.mirrors table a", func(h *colly.HTMLElement) { url := h.Attr("href") if strings.HasPrefix(url, "http:") || strings.HasPrefix(url, "https:") || strings.HasPrefix(url, "ftp:") { if !strings.HasSuffix(url, "/") { url += "/" } repoMirrors <- RepoMirror{d.GetName(), DefaultRepo, url} } }) c.Visit("https://mirrors.alpinelinux.org/") c.Wait() }