-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
38 lines (31 loc) · 872 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"performance-and-scalability-of-go-applications/05-scheduler/wordlinecount/wlc"
)
// URL of the txt file to analyze
const url string = "https://www.gutenberg.org/files/16/16-0.txt"
// number of files to analyze
const nReaders int = 8
func main() {
word := flag.String("word", "", "word to search")
flag.Parse()
// in order to keep it simple, we read nReaders time from the same URL
readers := make([]io.Reader, nReaders)
for i := range readers {
// Do the GET request
resp, err := http.Get(url)
if err != nil {
log.Fatalf("could not perform GET request to url %s", url)
}
defer resp.Body.Close()
// save the http response body as reader interface
readers[i] = resp.Body
}
// calculate total number of lines in which word appear
fmt.Println(wlc.WordLineCount(readers, *word))
}