shad-go/lectures/06-http/keepalive/naive/naive.go

31 lines
478 B
Go
Raw Normal View History

2020-04-02 11:42:31 +00:00
package main
import (
"fmt"
"net/http"
"sync"
)
func main() {
urls := []string{"https://golang.org/doc", "https://golang.org/pkg", "https://golang.org/help"}
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(url string) {
defer wg.Done()
var client http.Client
resp, err := client.Get(url)
if err != nil {
fmt.Printf("%s: %s\n", url, err)
return
}
fmt.Printf("%s - %d\n", url, resp.StatusCode)
}(url)
}
wg.Wait()
}