Created
November 9, 2019 08:55
-
-
Save kasvith/bcc2f224fc950cfd632d2f6a6665b2e9 to your computer and use it in GitHub Desktop.
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
// isAlive checks whether a backend is Alive by establishing a TCP connection | |
func isBackendAlive(u *url.URL) bool { | |
timeout := 2 * time.Second | |
conn, err := net.DialTimeout("tcp", u.Host, timeout) | |
if err != nil { | |
log.Println("Site unreachable, error: ", err) | |
return false | |
} | |
_ = conn.Close() // close it, we dont need to maintain this connection | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment