mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
2989b8b2c5
Several types contained redundant references to ControlRuntime data. Switch to consistently accessing this via config.Runtime instead. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
30 lines
803 B
Go
30 lines
803 B
Go
package cluster
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// getHandler returns a basic request handler that processes requests through
|
|
// the cluster's request router chain.
|
|
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
|
|
}
|
|
|
|
// router is a stub request router that returns a Service Unavailable response
|
|
// if no additional handlers are available.
|
|
func (c *Cluster) router() http.Handler {
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
|
if c.config.Runtime.Handler == nil {
|
|
http.Error(rw, "starting", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
|
|
c.config.Runtime.Handler.ServeHTTP(rw, req)
|
|
})
|
|
}
|