mirror of https://github.com/docker/docs.git
API: Move routes outside of createRouter.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
f27a7b8357
commit
c1a6d14792
118
api/api.go
118
api/api.go
|
@ -26,6 +26,63 @@ import (
|
|||
// The Client API version
|
||||
const APIVERSION = "1.16"
|
||||
|
||||
var routes = map[string]map[string]handler{
|
||||
"GET": {
|
||||
"/_ping": ping,
|
||||
"/events": getEvents,
|
||||
"/info": getInfo,
|
||||
"/version": getVersion,
|
||||
"/images/json": getImagesJSON,
|
||||
"/images/viz": notImplementedHandler,
|
||||
"/images/search": proxyRandom,
|
||||
"/images/get": notImplementedHandler,
|
||||
"/images/{name:.*}/get": proxyImage,
|
||||
"/images/{name:.*}/history": proxyImage,
|
||||
"/images/{name:.*}/json": proxyImage,
|
||||
"/containers/ps": getContainersJSON,
|
||||
"/containers/json": getContainersJSON,
|
||||
"/containers/{name:.*}/export": proxyContainer,
|
||||
"/containers/{name:.*}/changes": proxyContainer,
|
||||
"/containers/{name:.*}/json": getContainerJSON,
|
||||
"/containers/{name:.*}/top": proxyContainer,
|
||||
"/containers/{name:.*}/logs": proxyContainer,
|
||||
"/containers/{name:.*}/stats": proxyContainer,
|
||||
"/containers/{name:.*}/attach/ws": proxyHijack,
|
||||
"/exec/{execid:.*}/json": proxyContainer,
|
||||
},
|
||||
"POST": {
|
||||
"/auth": proxyRandom,
|
||||
"/commit": postCommit,
|
||||
"/build": notImplementedHandler,
|
||||
"/images/create": postImagesCreate,
|
||||
"/images/load": notImplementedHandler,
|
||||
"/images/{name:.*}/push": proxyImage,
|
||||
"/images/{name:.*}/tag": proxyImage,
|
||||
"/containers/create": postContainersCreate,
|
||||
"/containers/{name:.*}/kill": proxyContainer,
|
||||
"/containers/{name:.*}/pause": proxyContainer,
|
||||
"/containers/{name:.*}/unpause": proxyContainer,
|
||||
"/containers/{name:.*}/rename": proxyContainer,
|
||||
"/containers/{name:.*}/restart": proxyContainer,
|
||||
"/containers/{name:.*}/start": proxyContainer,
|
||||
"/containers/{name:.*}/stop": proxyContainer,
|
||||
"/containers/{name:.*}/wait": proxyContainer,
|
||||
"/containers/{name:.*}/resize": proxyContainer,
|
||||
"/containers/{name:.*}/attach": proxyHijack,
|
||||
"/containers/{name:.*}/copy": proxyContainer,
|
||||
"/containers/{name:.*}/exec": postContainersExec,
|
||||
"/exec/{execid:.*}/start": proxyHijack,
|
||||
"/exec/{execid:.*}/resize": proxyContainer,
|
||||
},
|
||||
"DELETE": {
|
||||
"/containers/{name:.*}": deleteContainers,
|
||||
"/images/{name:.*}": deleteImages,
|
||||
},
|
||||
"OPTIONS": {
|
||||
"": optionsHandler,
|
||||
},
|
||||
}
|
||||
|
||||
type context struct {
|
||||
cluster cluster.Cluster
|
||||
eventsHandler *eventsHandler
|
||||
|
@ -487,65 +544,8 @@ func httpError(w http.ResponseWriter, err string, status int) {
|
|||
|
||||
func createRouter(c *context, enableCors bool) *mux.Router {
|
||||
r := mux.NewRouter()
|
||||
m := map[string]map[string]handler{
|
||||
"GET": {
|
||||
"/_ping": ping,
|
||||
"/events": getEvents,
|
||||
"/info": getInfo,
|
||||
"/version": getVersion,
|
||||
"/images/json": getImagesJSON,
|
||||
"/images/viz": notImplementedHandler,
|
||||
"/images/search": proxyRandom,
|
||||
"/images/get": notImplementedHandler,
|
||||
"/images/{name:.*}/get": proxyImage,
|
||||
"/images/{name:.*}/history": proxyImage,
|
||||
"/images/{name:.*}/json": proxyImage,
|
||||
"/containers/ps": getContainersJSON,
|
||||
"/containers/json": getContainersJSON,
|
||||
"/containers/{name:.*}/export": proxyContainer,
|
||||
"/containers/{name:.*}/changes": proxyContainer,
|
||||
"/containers/{name:.*}/json": getContainerJSON,
|
||||
"/containers/{name:.*}/top": proxyContainer,
|
||||
"/containers/{name:.*}/logs": proxyContainer,
|
||||
"/containers/{name:.*}/stats": proxyContainer,
|
||||
"/containers/{name:.*}/attach/ws": proxyHijack,
|
||||
"/exec/{execid:.*}/json": proxyContainer,
|
||||
},
|
||||
"POST": {
|
||||
"/auth": proxyRandom,
|
||||
"/commit": postCommit,
|
||||
"/build": notImplementedHandler,
|
||||
"/images/create": postImagesCreate,
|
||||
"/images/load": notImplementedHandler,
|
||||
"/images/{name:.*}/push": proxyImage,
|
||||
"/images/{name:.*}/tag": proxyImage,
|
||||
"/containers/create": postContainersCreate,
|
||||
"/containers/{name:.*}/kill": proxyContainer,
|
||||
"/containers/{name:.*}/pause": proxyContainer,
|
||||
"/containers/{name:.*}/unpause": proxyContainer,
|
||||
"/containers/{name:.*}/rename": proxyContainer,
|
||||
"/containers/{name:.*}/restart": proxyContainer,
|
||||
"/containers/{name:.*}/start": proxyContainer,
|
||||
"/containers/{name:.*}/stop": proxyContainer,
|
||||
"/containers/{name:.*}/wait": proxyContainer,
|
||||
"/containers/{name:.*}/resize": proxyContainer,
|
||||
"/containers/{name:.*}/attach": proxyHijack,
|
||||
"/containers/{name:.*}/copy": proxyContainer,
|
||||
"/containers/{name:.*}/exec": postContainersExec,
|
||||
"/exec/{execid:.*}/start": proxyHijack,
|
||||
"/exec/{execid:.*}/resize": proxyContainer,
|
||||
},
|
||||
"DELETE": {
|
||||
"/containers/{name:.*}": deleteContainers,
|
||||
"/images/{name:.*}": deleteImages,
|
||||
},
|
||||
"OPTIONS": {
|
||||
"": optionsHandler,
|
||||
},
|
||||
}
|
||||
|
||||
for method, routes := range m {
|
||||
for route, fct := range routes {
|
||||
for method, mappings := range routes {
|
||||
for route, fct := range mappings {
|
||||
log.WithFields(log.Fields{"method": method, "route": route}).Debug("Registering HTTP route")
|
||||
|
||||
// NOTE: scope issue, make sure the variables are local and won't be changed
|
||||
|
|
Loading…
Reference in New Issue