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