mirror of https://github.com/nmasse-itix/liche.git
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.
35 lines
527 B
35 lines
527 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 {
|
|
_, err := c.client.Get(s)
|
|
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)
|
|
}
|
|
|