github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/server/router/container/container.go (about) 1 package container 2 3 import ( 4 5 "fmt" 6 7 "github.com/docker/docker/api/server/httputils" 8 "github.com/docker/docker/api/server/router" 9 ) 10 11 type validationError struct { 12 error 13 } 14 15 func (validationError) IsValidationError() bool { 16 return true 17 } 18 19 // containerRouter is a router to talk with the container controller 20 type containerRouter struct { 21 backend Backend 22 decoder httputils.ContainerDecoder 23 routes []router.Route 24 } 25 26 // NewRouter initializes a new container router 27 func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router { 28 fmt.Println("api/server/router/container/container.go NewRouter()") 29 r := &containerRouter{ 30 backend: b, 31 decoder: decoder, 32 } 33 r.initRoutes() 34 return r 35 } 36 37 // Routes returns the available routes to the container controller 38 func (r *containerRouter) Routes() []router.Route { 39 fmt.Println("api/server/router/container/container.go Routes()") 40 return r.routes 41 } 42 43 // initRoutes initializes the routes in container router 44 func (r *containerRouter) initRoutes() { 45 fmt.Println("api/server/router/container/container.go initRoutes()") 46 r.routes = []router.Route{ 47 // HEAD 48 router.NewHeadRoute("/containers/{name:.*}/archive", r.headContainersArchive), 49 // GET 50 router.NewGetRoute("/containers/json", r.getContainersJSON), 51 router.NewGetRoute("/containers/{name:.*}/export", r.getContainersExport), 52 router.NewGetRoute("/containers/{name:.*}/changes", r.getContainersChanges), 53 router.NewGetRoute("/containers/{name:.*}/json", r.getContainersByName), 54 router.NewGetRoute("/containers/{name:.*}/top", r.getContainersTop), 55 router.Cancellable(router.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs)), 56 router.Cancellable(router.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats)), 57 router.NewGetRoute("/containers/{name:.*}/attach/ws", r.wsContainersAttach), 58 router.NewGetRoute("/exec/{id:.*}/json", r.getExecByID), 59 router.NewGetRoute("/containers/{name:.*}/archive", r.getContainersArchive), 60 // POST 61 router.NewPostRoute("/containers/create", r.postContainersCreate), 62 router.NewPostRoute("/containers/{name:.*}/kill", r.postContainersKill), 63 router.NewPostRoute("/containers/{name:.*}/pause", r.postContainersPause), 64 router.NewPostRoute("/containers/{name:.*}/unpause", r.postContainersUnpause), 65 router.NewPostRoute("/containers/{name:.*}/restart", r.postContainersRestart), 66 router.NewPostRoute("/containers/{name:.*}/start", r.postContainersStart), 67 router.NewPostRoute("/containers/{name:.*}/stop", r.postContainersStop), 68 router.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait), 69 router.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize), 70 router.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach), 71 router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy), // Deprecated since 1.8, Errors out since 1.12 72 router.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate), 73 router.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart), 74 router.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize), 75 router.NewPostRoute("/containers/{name:.*}/rename", r.postContainerRename), 76 router.NewPostRoute("/containers/{name:.*}/update", r.postContainerUpdate), 77 router.NewPostRoute("/containers/prune", r.postContainersPrune), 78 // PUT 79 router.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive), 80 // DELETE 81 router.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers), 82 } 83 }