Beispiel #1
0
func (i Index) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	mux.BaseMux().HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		status := http.StatusOK
		if r.URL.Path != "/" && r.URL.Path != "/index.html" {
			// Since "/" matches all paths, handleIndex is called for all paths for which there is no handler registered.
			// We want to return a 404 status with a list of all valid paths, incase of an invalid URL request.
			status = http.StatusNotFound
		}
		var handledPaths []string
		// Extract the paths handled using restful.WebService
		for _, ws := range c.RegisteredWebServices() {
			handledPaths = append(handledPaths, ws.RootPath())
		}
		// Extract the paths handled using mux handler.
		handledPaths = append(handledPaths, mux.HandledPaths()...)
		sort.Strings(handledPaths)
		apiserver.WriteRawJSON(status, unversioned.RootPaths{Paths: handledPaths}, w)
	})
}
Beispiel #2
0
// Install adds the Profiling webservice to the given mux.
func (d Profiling) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	mux.BaseMux().HandleFunc("/debug/pprof/", pprof.Index)
	mux.BaseMux().HandleFunc("/debug/pprof/profile", pprof.Profile)
	mux.BaseMux().HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}