simple google 1.0

This commit is contained in:
Stephen McQuay 2013-05-14 20:48:43 -07:00
commit 9dfb55deee
2 changed files with 51 additions and 0 deletions

18
main.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"fmt"
"time"
"math/rand"
)
func main() {
rand.Seed(time.Now().UnixNano())
start := time.Now()
results := Google("golang")
elapsed := time.Since(start)
fmt.Println(results)
fmt.Println(elapsed)
}

33
search.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"fmt"
"math/rand"
"time"
)
var (
Web = fakeSearch("web")
Image = fakeSearch("image")
Video = fakeSearch("video")
)
type Search func(query string) Result
type Result struct {
Goodies string
}
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)}
}
}
func Google(query string) (results []Result) {
results = append(results, Web(query))
results = append(results, Image(query))
results = append(results, Video(query))
return
}