github.com/cookieai-jar/moby@v17.12.1-ce-rc2+incompatible/api/server/router/experimental.go (about) 1 package router 2 3 import ( 4 "net/http" 5 6 "golang.org/x/net/context" 7 8 "github.com/docker/docker/api/server/httputils" 9 ) 10 11 // ExperimentalRoute defines an experimental API route that can be enabled or disabled. 12 type ExperimentalRoute interface { 13 Route 14 15 Enable() 16 Disable() 17 } 18 19 // experimentalRoute defines an experimental API route that can be enabled or disabled. 20 // It implements ExperimentalRoute 21 type experimentalRoute struct { 22 local Route 23 handler httputils.APIFunc 24 } 25 26 // Enable enables this experimental route 27 func (r *experimentalRoute) Enable() { 28 r.handler = r.local.Handler() 29 } 30 31 // Disable disables the experimental route 32 func (r *experimentalRoute) Disable() { 33 r.handler = experimentalHandler 34 } 35 36 type notImplementedError struct{} 37 38 func (notImplementedError) Error() string { 39 return "This experimental feature is disabled by default. Start the Docker daemon in experimental mode in order to enable it." 40 } 41 42 func (notImplementedError) NotImplemented() {} 43 44 func experimentalHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { 45 return notImplementedError{} 46 } 47 48 // Handler returns returns the APIFunc to let the server wrap it in middlewares. 49 func (r *experimentalRoute) Handler() httputils.APIFunc { 50 return r.handler 51 } 52 53 // Method returns the http method that the route responds to. 54 func (r *experimentalRoute) Method() string { 55 return r.local.Method() 56 } 57 58 // Path returns the subpath where the route responds to. 59 func (r *experimentalRoute) Path() string { 60 return r.local.Path() 61 } 62 63 // Experimental will mark a route as experimental. 64 func Experimental(r Route) Route { 65 return &experimentalRoute{ 66 local: r, 67 handler: experimentalHandler, 68 } 69 }