1
0
Fork 0
squid-rewriter/distro/debian.go

42 lines
864 B
Go

package distro
import (
"strings"
"sync"
"github.com/gocolly/colly"
)
type Debian struct{}
func (d Debian) GetName() string {
return "debian"
}
func (d Debian) GetRepos() []string {
return []string{DefaultRepo}
}
func (d Debian) FetchMirrors(repos []string, repoMirrors chan<- RepoMirror, done *sync.WaitGroup) {
defer done.Done()
c := colly.NewCollector(
colly.AllowedDomains("www.debian.org"),
)
c.OnHTML("h2#complete-list+table", func(h *colly.HTMLElement) {
h.ForEach("a", func(i int, 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://www.debian.org/mirror/list")
c.Wait()
}