-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (41 loc) · 773 Bytes
/
main.go
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
package main
import (
"time"
"net/http"
"fmt"
)
func main(){
links := []string{
"https://google.com",
"https://flipkart.com",
"https://amazon.com",
"https://stackoverflow.com",
"https://netflix.com",
}
c := make(chan string)
for _, link := range links{
go checkLink(link, c)
}
// Reading a message from channel is blocking operation
// fmt.Println(<-c)
// fmt.Println(<-c)
// fmt.Println(<-c)
// fmt.Println(<-c)
// fmt.Println(<-c)
for l := range c{
// go checkLink(l, c)
go func (l string) {
time.Sleep(time.Second*2)
checkLink(l, c)
}(l)
}
}
func checkLink(link string, c chan string){
if _, err := http.Get(link); err != nil{
fmt.Println(link, "is down")
c <- link
return
}
fmt.Println(link, "is up")
c <- link
}