Fast Link Checker for Markdown and HTML in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
590 B

package main
import (
"net/http"
"sync"
"time"
)
type urlChecker struct {
client http.Client
}
func newURLChecker(timeout time.Duration) urlChecker {
return urlChecker{http.Client{Timeout: timeout}}
}
func (c urlChecker) Check(s string) error {
res, err := c.client.Get(s)
if err != nil && res != nil {
defer res.Body.Close()
}
return err
}
func (c urlChecker) CheckMany(ss []string, rc chan<- urlResult) {
wg := sync.WaitGroup{}
for _, s := range ss {
wg.Add(1)
go func(s string) {
rc <- urlResult{s, c.Check(s)}
wg.Done()
}(s)
}
wg.Wait()
close(rc)
}