2019-10-27 05:53:25 +00:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2020-09-24 06:29:25 +00:00
|
|
|
// getHandler returns a basic request handler that processes requests through
|
|
|
|
// the cluster's request router chain.
|
2019-10-27 05:53:25 +00:00
|
|
|
func (c *Cluster) getHandler(handler http.Handler) (http.Handler, error) {
|
|
|
|
next := c.router()
|
|
|
|
|
|
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
|
|
|
handler.ServeHTTP(rw, req)
|
|
|
|
next.ServeHTTP(rw, req)
|
|
|
|
}), nil
|
|
|
|
}
|
|
|
|
|
2020-09-24 06:29:25 +00:00
|
|
|
// router is a stub request router that returns a Service Unavailable response
|
|
|
|
// if no additional handlers are available.
|
2019-10-27 05:53:25 +00:00
|
|
|
func (c *Cluster) router() http.Handler {
|
|
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
|
|
|
if c.runtime.Handler == nil {
|
|
|
|
http.Error(rw, "starting", http.StatusServiceUnavailable)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.runtime.Handler.ServeHTTP(rw, req)
|
|
|
|
})
|
|
|
|
}
|