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

32 lines
578 B
Go
Raw Permalink Normal View History

2020-04-02 11:42:31 +00:00
package main
import (
"crypto/tls"
"fmt"
"net/http"
"sync"
)
func main() {
urls := []string{"https://golang.org/doc", "https://golang.org/pkg", "https://golang.org/help"}
client := &http.Client{
2020-04-02 14:01:16 +00:00
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
2020-04-02 11:42:31 +00:00
}
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(url string) {
defer wg.Done()
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()
}