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:
nikhiljindal
2015-01-15 16:18:47 -08:00
parent 790a78415e
commit 51007cc798
5 changed files with 77 additions and 21 deletions

View File

@@ -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)
}
}