mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
Updating handleIndex in master to list all valid paths.
The list of valid paths is computed from http.ServeMux and restful.WebService. Adding a mux helper - wrapper over mux, that keeps track of the paths handled by mux.
This commit is contained in:
@@ -17,11 +17,24 @@ limitations under the License.
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
)
|
||||
|
||||
// handleIndex is the root index page for Kubernetes.
|
||||
func HandleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, "<html><body>Welcome to Kubernetes</body></html>")
|
||||
func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var handledPaths []string
|
||||
// Extract the paths handled using restful.WebService
|
||||
for _, ws := range container.RegisteredWebServices() {
|
||||
handledPaths = append(handledPaths, ws.RootPath())
|
||||
}
|
||||
// Extract the paths handled using mux handler.
|
||||
handledPaths = append(handledPaths, muxHelper.RegisteredPaths...)
|
||||
sort.Strings(handledPaths)
|
||||
writeRawJSON(http.StatusOK, api.RootPaths{Paths: handledPaths}, w)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user