completion of crawler worker mode. tests still passing!

This commit is contained in:
swaits committed 2015-02-17 09:28:24 -08:00
1 parent 3f85a0e7c0
commit 13b84ee452
1 file changed
+7 -13
+7 -13
View File
@@ -119,36 +119,30 @@ func crawlListner(txchan <-chan *httpItem, rxchan chan<- *httpItem) {
// channel closed, finish // channel closed, finish
return return
} }
crawlItem(newJob, rxchan) // perform the crawl
rxchan <- crawlItem(newJob)
} }
} }
} }
// crawlItem crawls a single httpItem, fetching the header, hte page, parsing it, // crawlItem crawls a single httpItem, fetching the header, hte page, parsing it,
// and filling out its structure as much as possible // and filling out its structure as much as possible
func crawlItem(item *httpItem, rxchan chan<- *httpItem) { func crawlItem(item *httpItem) *httpItem {
// make sure this item is the same domain (i.e. URL "host part") as its referrer // make sure this item is the same domain (i.e. URL "host part") as its referrer
if item.refurl != nil && item.url.Host != item.refurl.Host { if item.refurl != nil && item.url.Host != item.refurl.Host {
// skip URLs associated with other Hosts // skip URLs associated with other Hosts
item.linkType = tRemote item.linkType = tRemote
rxchan <- item return item
return
} }
// fetch page // fetch page
text, err := fetchPage(item) text, err := fetchPage(item)
if err != nil { if err != nil {
rxchan <- item return item
return
} }
// parse links // parse links
title, links := parseLinks(text) // TODO remove error from parseLinks, not needed title, links := parseLinks(text)
if err != nil {
item.linkType = tBroken
rxchan <- item
return
}
item.title = title item.title = title
// walk links and add them as children to the current item // walk links and add them as children to the current item
@@ -161,7 +155,7 @@ func crawlItem(item *httpItem, rxchan chan<- *httpItem) {
} }
// send back our item struct now that it's all filled out // send back our item struct now that it's all filled out
rxchan <- item return item
} }
func main() { func main() {