func processLines(done chan<- struct{}, pageMap safemap.SafeMap, lines <-chan string) { getRx := regexp.MustCompile(`GET[ \t]+([^ \t\n]+[.]html?)`) incrementer := func(value interface{}, found bool) interface{} { if found { return value.(int) + 1 } return 1 } for i := 0; i < workers; i++ { go func() { for line := range lines { if matches := getRx.FindStringSubmatch(line); matches != nil { pageMap.Update(matches[1], incrementer) } } done <- struct{}{} }() } }
func showResults(pageMap safemap.SafeMap) { pages := pageMap.Close() for page, count := range pages { fmt.Printf("%8d %s\n", count, page) } }