Created
November 9, 2019 08:42
-
-
Save kasvith/ed35e205c7e91fd72c9146809365130b 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
// lb load balances the incoming request | |
func lb(w http.ResponseWriter, r *http.Request) { | |
attempts := GetAttemptsFromContext(r) | |
if attempts > 3 { | |
log.Printf("%s(%s) Max attempts reached, terminating\n", r.RemoteAddr, r.URL.Path) | |
http.Error(w, "Service not available", http.StatusServiceUnavailable) | |
return | |
} | |
peer := serverPool.GetNextPeer() | |
if peer != nil { | |
peer.ReverseProxy.ServeHTTP(w, r) | |
return | |
} | |
http.Error(w, "Service not available", http.StatusServiceUnavailable) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment