move API handlers in webservice resource files

This commit is contained in:
Wang Xin
2018-05-31 19:51:46 +08:00
parent 1a1cd8f644
commit 786eaefb7d
5 changed files with 57 additions and 71 deletions

View File

@@ -4,11 +4,25 @@ import (
"github.com/emicklei/go-restful"
"kubesphere.io/kubesphere/pkg/filter/route"
"kubesphere.io/kubesphere/pkg/models"
"net/http"
)
func Register(ws *restful.WebService, subPath string) {
ws.Route(ws.GET(subPath+"/namespaces/{namespace}/persistentvolumeclaims/{pvc}/pods").
To(models.GetPodListByPvc).Filter(route.RouteLogging)).
To(GetPodListByPvc).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
}
// List all pods of a specific PVC
// Extended API URL: "GET /api/v1alpha/volumes/namespaces/{namespace}/persistentvolumeclaims/{name}/pods"
func GetPodListByPvc(request *restful.Request, response *restful.Response) {
pvcName := request.PathParameter("pvc")
nsName := request.PathParameter("namespace")
pods, err := models.GetPodListByPvc(pvcName, nsName)
if err != nil {
response.WriteError(http.StatusInternalServerError, err)
}
result := models.PodListByPvc{Name: pvcName, Namespace: nsName, Pods: pods}
response.WriteAsJson(result)
}