Skip to content

Instantly share code, notes, and snippets.

@kasvith
Created November 9, 2019 08:55
Show Gist options
  • Save kasvith/bcc2f224fc950cfd632d2f6a6665b2e9 to your computer and use it in GitHub Desktop.
Save kasvith/bcc2f224fc950cfd632d2f6a6665b2e9 to your computer and use it in GitHub Desktop.

Revisions

  1. kasvith created this gist Nov 9, 2019.
    11 changes: 11 additions & 0 deletions lb.snip6.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // 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
    }