Merge from develop

This commit is contained in:
swaits committed 2015-02-17 08:57:14 -08:00
commit af148c3a8a
1 file changed
+5 -8
+5 -8
View File
@@ -9,7 +9,7 @@ import (
// docrawl begins crawling the site at "homeurl" // docrawl begins crawling the site at "homeurl"
func doCrawl(homeurl string) itemSlice { func doCrawl(homeurl string) itemSlice {
// set of what we have already crawled // set of what we have already crawled, our results
crawled := make(itemMap) crawled := make(itemMap)
// a set of crawled URLs which have been cleaned // a set of crawled URLs which have been cleaned
@@ -17,9 +17,6 @@ func doCrawl(homeurl string) itemSlice {
// already crawled http://a.com/index.html, or vice versa // already crawled http://a.com/index.html, or vice versa
crawledStripped := make(itemMap) crawledStripped := make(itemMap)
// map (of urlString -> httpItem) of our results
results := make(itemMap)
// a channel to receive our results on // a channel to receive our results on
rchan := make(chan *httpItem) rchan := make(chan *httpItem)
@@ -45,7 +42,7 @@ func doCrawl(homeurl string) itemSlice {
select { select {
case r := <-rchan: // new results? case r := <-rchan: // new results?
// add result to our results map // add result to our results map
results[r.url.String()] = r crawled[r.url.String()] = r
// decrease the outstanding page count by 1 // decrease the outstanding page count by 1
crawlingCount-- crawlingCount--
@@ -54,7 +51,7 @@ func doCrawl(homeurl string) itemSlice {
for i, c := range r.children { for i, c := range r.children {
// see if we already have a result for this page // see if we already have a result for this page
// if so, point to that result // if so, point to that result
if existing, ok := results[c.url.String()]; ok { if existing, ok := crawled[c.url.String()]; ok {
r.children[i] = existing r.children[i] = existing
continue continue
} }
@@ -85,13 +82,13 @@ func doCrawl(homeurl string) itemSlice {
case <-ticker: // our regular ticker. for status output and checking for completion. case <-ticker: // our regular ticker. for status output and checking for completion.
// output status to console // output status to console
log.Printf("Crawled %v links, have %v left.\n", len(results), crawlingCount) log.Printf("Crawled %v links, have %v left.\n", len(crawled), crawlingCount)
// see if we're finished // see if we're finished
if crawlingCount == 0 { if crawlingCount == 0 {
// finished! convert results map to a slice and return it // finished! convert results map to a slice and return it
rslice := itemSlice{} rslice := itemSlice{}
for _, v := range results { for _, v := range crawled {
rslice = append(rslice, v) rslice = append(rslice, v)
} }
return rslice return rslice