func (l Logs) Install(c *mux.APIContainer) { // use restful: ws.Route(ws.GET("/logs/{logpath:*}").To(fileHandler)) // See github.com/emicklei/go-restful/blob/master/examples/restful-serve-static.go ws := new(restful.WebService) ws.Path("/logs") ws.Doc("get log files") ws.Route(ws.GET("/{logpath:*}").To(logFileHandler).Param(ws.PathParameter("logpath", "path to the log").DataType("string"))) ws.Route(ws.GET("/").To(logFileListHandler)) c.Add(ws) }
// Install registers the APIServer's `/version` handler. func (v Version) Install(c *mux.APIContainer) { if v.Version == nil { return } // Set up a service to return the git code version. versionWS := new(restful.WebService) versionWS.Path("/version") versionWS.Doc("git code version from which this is built") versionWS.Route( versionWS.GET("/").To(v.handleVersion). Doc("get the code version"). Operation("getCodeVersion"). Produces(restful.MIME_JSON). Consumes(restful.MIME_JSON). Writes(version.Info{})) c.Add(versionWS) }
// Install adds the Index webservice to the given mux. func (i Index) Install(c *mux.APIContainer) { c.UnlistedRoutes.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 api.Registry. // 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, c.NonSwaggerRoutes.HandledPaths()...) sort.Strings(handledPaths) responsewriters.WriteRawJSON(status, metav1.RootPaths{Paths: handledPaths}, w) }) }
// Install adds the SwaggerUI webservice to the given mux. func (s Swagger) Install(c *mux.APIContainer) { s.Config.WebServices = c.RegisteredWebServices() swagger.RegisterSwaggerService(*s.Config, c.Container) }
// Install adds the SwaggerUI webservice to the given mux. func (oa OpenAPI) Install(c *mux.APIContainer) { err := apiserveropenapi.RegisterOpenAPIService("/swagger.json", c.RegisteredWebServices(), oa.Config, c) if err != nil { glog.Fatalf("Failed to register open api spec for root: %v", err) } }