Skip to content

Instantly share code, notes, and snippets.

@zaz600
Last active December 7, 2016 21:19
Show Gist options
  • Save zaz600/89c5f122672222d139b4 to your computer and use it in GitHub Desktop.
Save zaz600/89c5f122672222d139b4 to your computer and use it in GitHub Desktop.
// web_check.go
package main
import (
"fmt"
"net/http"
"time"
)
const url = "https://golang.org/"
func main() {
check_loop()
}
func check_loop() {
for {
check(url)
time.Sleep(1 * time.Minute)
}
}
func check(url string) {
fmt.Println("Проверяем адрес ", url)
resp, err := http.Get(url)
if err != nil {
fmt.Printf("Ошибка соединения. %s\n", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
fmt.Printf("Ошибка. http-статус: %s\n", resp.StatusCode)
return
}
fmt.Printf("Онлайн. http-статус: %d\n", resp.StatusCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment