Skip to content

Instantly share code, notes, and snippets.

@kasvith
Created November 9, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasvith/bcc2f224fc950cfd632d2f6a6665b2e9 to your computer and use it in GitHub Desktop.
Save kasvith/bcc2f224fc950cfd632d2f6a6665b2e9 to your computer and use it in GitHub Desktop.
// 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