Skip to content

Instantly share code, notes, and snippets.

@belohlavek
Last active May 28, 2017 14:51
Show Gist options
  • Save belohlavek/6aab1abdc6069fd07c269b328d43abd6 to your computer and use it in GitHub Desktop.
Save belohlavek/6aab1abdc6069fd07c269b328d43abd6 to your computer and use it in GitHub Desktop.
Micro poller written in go
package main
// go run poller.go --interval 1
import (
"flag"
"log"
"net/http"
"time"
)
func poll(url string) string {
resp, err := http.Head(url)
if err != nil {
log.Println("Error", url, err)
return err.Error()
}
log.Println("Status", url, resp.Status)
return resp.Status
}
func main() {
targetPtr := flag.String("target", "http://google.com", "Polling target url")
intervalPtr := flag.Int("interval", 60, "Polling interval in seconds")
flag.Parse()
for {
poll(*targetPtr)
time.Sleep(time.Duration(*intervalPtr) * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment