Example #1
0
func (l SwaggerUI) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	fileServer := http.FileServer(&assetfs.AssetFS{
		Asset:    swagger.Asset,
		AssetDir: swagger.AssetDir,
		Prefix:   "third_party/swagger-ui",
	})
	prefix := "/swagger-ui/"
	mux.Handle(prefix, http.StripPrefix(prefix, fileServer))
}
Example #2
0
func (m MetricsWithReset) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	defaultMetricsHandler := prometheus.Handler().ServeHTTP
	mux.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
		if req.Method == "DELETE" {
			apiservermetrics.Reset()
			etcdmetrics.Reset()
			io.WriteString(w, "metrics reset\n")
			return
		}
		defaultMetricsHandler(w, req)
	})
}
Example #3
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)
	})
}
Example #4
0
func (m DefaultMetrics) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	mux.HandleFunc("/metrics", prometheus.Handler().ServeHTTP)
}
Example #5
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)
}
Example #6
0
func (r UIRedirect) Install(mux *apiserver.PathRecorderMux, c *restful.Container) {
	mux.HandleFunc("/ui/", func(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, dashboardPath, http.StatusTemporaryRedirect)
	})
}