krovn

Untitled

Nov 10th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.54 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net/http"
  6. )
  7.  
  8. func main() {
  9.     links := []string{
  10.         "http://google.com",
  11.         "http://yahoo.com",
  12.         "http://sportacentrs.com",
  13.         "http://golang.org",
  14.         "http://facebook.com",
  15.     }
  16.     c := make(chan string)
  17.     for _, link := range links {
  18.         go checkLink(link, c)
  19.     }
  20.     for l := range c {
  21.         go checkLink(l, c)
  22.     }
  23. }
  24.  
  25. func checkLink(link string, c chan string) {
  26.     _, err := http.Get(link)
  27.     if err != nil {
  28.         fmt.Println(link, "might be down!")
  29.         c <- link
  30.         return
  31.     }
  32.     fmt.Println(link, "is up!")
  33.     c <- link
  34. }
Advertisement
Add Comment
Please, Sign In to add comment