simple google 1.0
This commit is contained in:
commit
9dfb55deee
18
main.go
Normal file
18
main.go
Normal 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
33
search.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user