package main import ( "fmt" "io/ioutil" "net/http" "time" ) type Data struct { length int duration time.Duration } func getPage(url string) (Data, error) { var d Data resp, err := http.Get(url) if err != nil { return d, err } defer resp.Body.Close() start := time.Now() body, err := ioutil.ReadAll(resp.Body) if err != nil { return d, err } dur := time.Since(start) d.length = len(body) d.duration = dur return d, nil } func main() { sites := map[string]string{ "Google": "http://google.com", "Yahoo": "http://yahoo.com", "Bing": "http://bing.com", } start := time.Now() for name, url := range sites { data, err := getPage(url) if err != nil { fmt.Printf("%s %s\n", name, err) } fmt.Printf("%-10s %6.2f KB %7.2f ms\n", name, float32(data.length)/1024, float32(data.duration)/1000000) } fmt.Printf("Total time: %.3f seconds\n", time.Since(start).Seconds()) }