Skip to content

Instantly share code, notes, and snippets.

@johnpc
Created March 20, 2019 04:26
Show Gist options
  • Save johnpc/76886518125ab7853d4dc6b7c72f98e7 to your computer and use it in GitHub Desktop.
Save johnpc/76886518125ab7853d4dc6b7c72f98e7 to your computer and use it in GitHub Desktop.
Very simple Go program to monitor uptime
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