github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/api/server/router/local.go (about) 1 package router 2 3 import "github.com/docker/docker/api/server/httputils" 4 5 // localRoute defines an individual API route to connect 6 // with the docker daemon. It implements Route. 7 type localRoute struct { 8 method string 9 path string 10 handler httputils.APIFunc 11 } 12 13 // Handler returns the APIFunc to let the server wrap it in middlewares. 14 func (l localRoute) Handler() httputils.APIFunc { 15 return l.handler 16 } 17 18 // Method returns the http method that the route responds to. 19 func (l localRoute) Method() string { 20 return l.method 21 } 22 23 // Path returns the subpath where the route responds to. 24 func (l localRoute) Path() string { 25 return l.path 26 } 27 28 // NewRoute initializes a new local route for the router. 29 func NewRoute(method, path string, handler httputils.APIFunc) Route { 30 return localRoute{method, path, handler} 31 } 32 33 // NewGetRoute initializes a new route with the http method GET. 34 func NewGetRoute(path string, handler httputils.APIFunc) Route { 35 return NewRoute("GET", path, handler) 36 } 37 38 // NewPostRoute initializes a new route with the http method POST. 39 func NewPostRoute(path string, handler httputils.APIFunc) Route { 40 return NewRoute("POST", path, handler) 41 } 42 43 // NewPutRoute initializes a new route with the http method PUT. 44 func NewPutRoute(path string, handler httputils.APIFunc) Route { 45 return NewRoute("PUT", path, handler) 46 } 47 48 // NewDeleteRoute initializes a new route with the http method DELETE. 49 func NewDeleteRoute(path string, handler httputils.APIFunc) Route { 50 return NewRoute("DELETE", path, handler) 51 } 52 53 // NewOptionsRoute initializes a new route with the http method OPTIONS. 54 func NewOptionsRoute(path string, handler httputils.APIFunc) Route { 55 return NewRoute("OPTIONS", path, handler) 56 } 57 58 // NewHeadRoute initializes a new route with the http method HEAD. 59 func NewHeadRoute(path string, handler httputils.APIFunc) Route { 60 return NewRoute("HEAD", path, handler) 61 }