container.go 3.1 KB

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