-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.go
54 lines (40 loc) · 965 Bytes
/
google.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// +build OMIT
// The comments in these files for the presentation tool used to generate the slides.
package main
import (
"fmt"
"math/rand"
"time"
)
type Result string
// START0 OMIT
func Google(query string) []Result {
var results []Result
results = append(results, Web(query))
results = append(results, Image(query))
results = append(results, Video(query))
return results
}
// STOP0 OMIT
// START1 OMIT
var (
Web = fakeSearch("web")
Image = fakeSearch("image")
Video = fakeSearch("video")
)
type Search func(query string) Result // HL
func fakeSearch(kind string) Search {
return func(query string) Result {
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
return Result(fmt.Sprintf("%s result for %q\n", kind, query))
}
}
// STOP1 OMIT
func main() {
rand.Seed(time.Now().UnixNano())
start := time.Now()
results := Google("golang") // HL
elapsed := time.Since(start)
fmt.Println(results)
fmt.Println(elapsed)
}