github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/server/router/local/local.go (about) 1 package local 2 3 import ( 4 "github.com/docker/docker/api/server/httputils" 5 dkrouter "github.com/docker/docker/api/server/router" 6 "github.com/docker/docker/daemon" 7 ) 8 9 // router is a docker router that talks with the local docker daemon. 10 type router struct { 11 daemon *daemon.Daemon 12 routes []dkrouter.Route 13 } 14 15 // localRoute defines an individual API route to connect with the docker daemon. 16 // It implements router.Route. 17 type localRoute struct { 18 method string 19 path string 20 handler httputils.APIFunc 21 } 22 23 // Handler returns the APIFunc to let the server wrap it in middlewares 24 func (l localRoute) Handler() httputils.APIFunc { 25 return l.handler 26 } 27 28 // Method returns the http method that the route responds to. 29 func (l localRoute) Method() string { 30 return l.method 31 } 32 33 // Path returns the subpath where the route responds to. 34 func (l localRoute) Path() string { 35 return l.path 36 } 37 38 // NewRoute initializes a new local router for the reouter 39 func NewRoute(method, path string, handler httputils.APIFunc) dkrouter.Route { 40 return localRoute{method, path, handler} 41 } 42 43 // NewGetRoute initializes a new route with the http method GET. 44 func NewGetRoute(path string, handler httputils.APIFunc) dkrouter.Route { 45 return NewRoute("GET", path, handler) 46 } 47 48 // NewPostRoute initializes a new route with the http method POST. 49 func NewPostRoute(path string, handler httputils.APIFunc) dkrouter.Route { 50 return NewRoute("POST", path, handler) 51 } 52 53 // NewPutRoute initializes a new route with the http method PUT. 54 func NewPutRoute(path string, handler httputils.APIFunc) dkrouter.Route { 55 return NewRoute("PUT", path, handler) 56 } 57 58 // NewDeleteRoute initializes a new route with the http method DELETE. 59 func NewDeleteRoute(path string, handler httputils.APIFunc) dkrouter.Route { 60 return NewRoute("DELETE", path, handler) 61 } 62 63 // NewOptionsRoute initializes a new route with the http method OPTIONS 64 func NewOptionsRoute(path string, handler httputils.APIFunc) dkrouter.Route { 65 return NewRoute("OPTIONS", path, handler) 66 } 67 68 // NewHeadRoute initializes a new route with the http method HEAD. 69 func NewHeadRoute(path string, handler httputils.APIFunc) dkrouter.Route { 70 return NewRoute("HEAD", path, handler) 71 } 72 73 // NewRouter initializes a local router with a new daemon. 74 func NewRouter(daemon *daemon.Daemon) dkrouter.Router { 75 r := &router{ 76 daemon: daemon, 77 } 78 r.initRoutes() 79 return r 80 } 81 82 // Routes returns the list of routes registered in the router. 83 func (r *router) Routes() []dkrouter.Route { 84 return r.routes 85 } 86 87 // initRoutes initializes the routes in this router 88 func (r *router) initRoutes() { 89 r.routes = []dkrouter.Route{ 90 // OPTIONS 91 // GET 92 NewGetRoute("/images/json", r.getImagesJSON), 93 NewGetRoute("/images/search", r.getImagesSearch), 94 NewGetRoute("/images/get", r.getImagesGet), 95 NewGetRoute("/images/{name:.*}/get", r.getImagesGet), 96 NewGetRoute("/images/{name:.*}/history", r.getImagesHistory), 97 NewGetRoute("/images/{name:.*}/json", r.getImagesByName), 98 // POST 99 NewPostRoute("/commit", r.postCommit), 100 NewPostRoute("/images/create", r.postImagesCreate), 101 NewPostRoute("/images/load", r.postImagesLoad), 102 NewPostRoute("/images/{name:.*}/push", r.postImagesPush), 103 NewPostRoute("/images/{name:.*}/tag", r.postImagesTag), 104 // DELETE 105 NewDeleteRoute("/images/{name:.*}", r.deleteImages), 106 } 107 }