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

40 lines
817 B
Go

package distro
import (
"strings"
"sync"
"github.com/gocolly/colly"
)
type Slackware struct{}
func (d Slackware) GetName() string {
return "slackware"
}
func (d Slackware) GetRepos() []string {
return []string{DefaultRepo}
}
func (d Slackware) FetchMirrors(repos []string, repoMirrors chan<- RepoMirror, done *sync.WaitGroup) {
defer done.Done()
c := colly.NewCollector(
colly.AllowedDomains("mirrors.slackware.com"),
)
c.OnHTML("body.list 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.slackware.com/mirrorlist/")
c.Wait()
}