Extreme Makeover: server refactoring

This commit is contained in:
Ludovic Fernandez 2018-06-11 11:36:03 +02:00 committed by Traefiker Bot
parent bddb4cc33c
commit eac20d61df
19 changed files with 2356 additions and 1965 deletions

View file

@ -10,19 +10,18 @@ import (
// has at least one active Server in respect to the healthchecks and if this
// is not the case, it will stop the middleware chain and respond with 503.
type EmptyBackendHandler struct {
lb healthcheck.LoadBalancer
next http.Handler
next healthcheck.BalancerHandler
}
// NewEmptyBackendHandler creates a new EmptyBackendHandler instance.
func NewEmptyBackendHandler(lb healthcheck.LoadBalancer, next http.Handler) *EmptyBackendHandler {
return &EmptyBackendHandler{lb: lb, next: next}
func NewEmptyBackendHandler(lb healthcheck.BalancerHandler) *EmptyBackendHandler {
return &EmptyBackendHandler{next: lb}
}
// ServeHTTP responds with 503 when there is no active Server and otherwise
// invokes the next handler in the middleware chain.
func (h *EmptyBackendHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
if len(h.lb.Servers()) == 0 {
if len(h.next.Servers()) == 0 {
rw.WriteHeader(http.StatusServiceUnavailable)
rw.Write([]byte(http.StatusText(http.StatusServiceUnavailable)))
} else {