Last active
May 28, 2017 14:51
-
-
Save belohlavek/6aab1abdc6069fd07c269b328d43abd6 to your computer and use it in GitHub Desktop.
Micro poller written in go
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 | |
// 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