Skip to content

Instantly share code, notes, and snippets.

@jasonmccallister jasonmccallister/main.go

Last active May 6, 2020
Embed
What would you like to do?
website-status-check
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
)
func main() {
wait := flag.Int("wait", 3, "the number of seconds to wait when checking the URL")
flag.Parse()
args := os.Args
if len(args) < 1 {
fmt.Println("you must pass a URL to monitor as the first argument")
flag.PrintDefaults()
os.Exit(1)
}
url := args[1]
var status int
for status != http.StatusOK {
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
if resp.StatusCode == 200 {
status = resp.StatusCode
break
}
log.Println(fmt.Sprintf("received the response code %d from %s", resp.StatusCode, url))
time.Sleep(time.Duration(*wait) * time.Second)
}
log.Println(fmt.Sprintf("received the response code 200 from %s", url))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.