-
Notifications
You must be signed in to change notification settings - Fork 0
/
channels.go
52 lines (45 loc) · 881 Bytes
/
channels.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
47
48
49
50
51
52
package main
/*
import (
"fmt"
"net/http"
)
func main() {
// A slice of sample websites
urls := []string{
"https://www.easyjet.com/",
"https://www.skyscanner.de/",
"https://www.ryanair.com",
"https://wizzair.com/",
"https://www.swiss.com/",
}
c := make(chan urlStatus)
for _, url := range urls {
go checkUrl(url, c)
}
result := make([]urlStatus, len(urls))
for i, _ := range result {
result[i] = <-c
if result[i].status {
fmt.Println(result[i].url, "is up.")
} else {
fmt.Println(result[i].url, "is down !!")
}
}
}
//checks and prints a message if a website is up or down
func checkUrl(url string, c chan urlStatus) {
_, err := http.Get(url)
if err != nil {
// The website is down
c <- urlStatus{url, false}
} else {
// The website is up
c <- urlStatus{url, true}
}
}
type urlStatus struct {
url string
status bool
}
*/