-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 669 Bytes
/
main.go
File metadata and controls
47 lines (39 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"sync"
)
var links []string = []string{
"http://google.com",
"http://facebook.com",
"http://stackoverflow.com",
"http://golang.org",
"http://amazon.com",
}
var wg sync.WaitGroup
func main() {
fmt.Println()
for _, link := range links {
go checkLink(link)
wg.Add(1)
}
wg.Wait()
}
func checkLink(link string) {
resp, err := http.Get(link)
content, err1 := ioutil.ReadAll(resp.Body)
if err1 != nil {
log.Fatalln(err1)
}
fmt.Printf("%T\n", content)
defer resp.Body.Close()
if err != nil {
fmt.Println(link, "might be down!")
return
}
fmt.Println(link, "is up!.")
wg.Done()
}