Last active
February 23, 2021 08:32
-
-
Save zaz600/af6c5e783fcca5f75238 to your computer and use it in GitHub Desktop.
web_check
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" | |
) | |
const url = "https://golang.org/" | |
func main() { | |
check(url) | |
} | |
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