init
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"mcquay.me/spider"
|
||||
)
|
||||
|
||||
const usage = "crawl <url>"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
failures := []spider.Link{}
|
||||
for p := range spider.Pages(os.Args[1]) {
|
||||
resp, err := http.Get(p.To)
|
||||
if err != nil {
|
||||
failures = append(failures, p)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
failures = append(failures, p)
|
||||
}
|
||||
}
|
||||
|
||||
if len(failures) > 0 {
|
||||
for _, f := range failures {
|
||||
fmt.Fprintf(os.Stderr, "%+v\n", f)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user