Created
March 20, 2019 04:26
-
-
Save johnpc/76886518125ab7853d4dc6b7c72f98e7 to your computer and use it in GitHub Desktop.
Very simple Go program to monitor uptime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"time" | |
) | |
func main() { | |
links := []string{ | |
"http://golang.org", | |
"http://amazon.com", | |
"http://johncorser.com", | |
"http://jpc.io", | |
} | |
c := make(chan string) | |
for _, link := range links { | |
go checkLink(link, c) | |
} | |
for l := range c { | |
go func(link string) { | |
time.Sleep(5 * time.Second) | |
checkLink(link, c) | |
}(l) | |
} | |
} | |
func checkLink(link string, c chan string) { | |
_, err := http.Get(link) | |
if err != nil { | |
fmt.Println(link, "might be down!") | |
c <- link | |
return | |
} | |
fmt.Println(link, "is up!") | |
c <- link | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment