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