Advertisement
Guest User

Untitled

a guest
May 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.58 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net/http"
  6.     "time"
  7. )
  8.  
  9. func main() {
  10.     links := []string{
  11.         "http://sportacentrs.com",
  12.         "http://tvnet.lv",
  13.         "unknown website",
  14.         "http://google.com",
  15.     }
  16.     c := make(chan string)
  17.     for _, n := range links {
  18.         go checkLink(n, c)
  19.     }
  20.     for li := range c {
  21.         go func(self string) {
  22.             time.Sleep(5 * time.Second)
  23.             checkLink(self, c)
  24.         }(li)
  25.     }
  26. }
  27.  
  28. func checkLink(link string, c chan string) {
  29.     _, err := http.Get(link)
  30.     if err != nil {
  31.         fmt.Println(link, "didnt work.")
  32.         c <- link
  33.         return
  34.     }
  35.     fmt.Println(link, "worked.")
  36.     c <- link
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement