github.com/cookieai-jar/moby@v17.12.1-ce-rc2+incompatible/api/server/router/container/container.go (about)

     1  package container
     2  
     3  import (
     4  	"github.com/docker/docker/api/server/httputils"
     5  	"github.com/docker/docker/api/server/router"
     6  )
     7  
     8  type validationError struct {
     9  	cause error
    10  }
    11  
    12  func (e validationError) Error() string {
    13  	return e.cause.Error()
    14  }
    15  
    16  func (e validationError) Cause() error {
    17  	return e.cause
    18  }
    19  
    20  func (e validationError) InvalidParameter() {}
    21  
    22  // containerRouter is a router to talk with the container controller
    23  type containerRouter struct {
    24  	backend Backend
    25  	decoder httputils.ContainerDecoder
    26  	routes  []router.Route
    27  }
    28  
    29  // NewRouter initializes a new container router
    30  func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {
    31  	r := &containerRouter{
    32  		backend: b,
    33  		decoder: decoder,
    34  	}
    35  	r.initRoutes()
    36  	return r
    37  }
    38  
    39  // Routes returns the available routes to the container controller
    40  func (r *containerRouter) Routes() []router.Route {
    41  	return r.routes
    42  }
    43  
    44  // initRoutes initializes the routes in container router
    45  func (r *containerRouter) 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.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs, router.WithCancel),
    56  		router.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats, router.WithCancel),
    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, router.WithCancel),
    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, router.WithCancel),
    78  		// PUT
    79  		router.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive),
    80  		// DELETE
    81  		router.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers),
    82  	}
    83  }