-
-
Save igor-arkhipov/bca7a8ef9c7be588d45bba271eda86c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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