2018-02-05 16:05:59 -05:00
|
|
|
package router // import "github.com/docker/docker/api/server/router"
|
2016-11-16 20:58:06 -05:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-11-16 20:58:06 -05:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/server/httputils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ExperimentalRoute defines an experimental API route that can be enabled or disabled.
|
|
|
|
type ExperimentalRoute interface {
|
|
|
|
Route
|
|
|
|
|
|
|
|
Enable()
|
|
|
|
Disable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// experimentalRoute defines an experimental API route that can be enabled or disabled.
|
|
|
|
// It implements ExperimentalRoute
|
|
|
|
type experimentalRoute struct {
|
|
|
|
local Route
|
|
|
|
handler httputils.APIFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable enables this experimental route
|
|
|
|
func (r *experimentalRoute) Enable() {
|
|
|
|
r.handler = r.local.Handler()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable disables the experimental route
|
|
|
|
func (r *experimentalRoute) Disable() {
|
|
|
|
r.handler = experimentalHandler
|
|
|
|
}
|
|
|
|
|
2017-07-19 10:20:13 -04:00
|
|
|
type notImplementedError struct{}
|
|
|
|
|
|
|
|
func (notImplementedError) Error() string {
|
|
|
|
return "This experimental feature is disabled by default. Start the Docker daemon in experimental mode in order to enable it."
|
|
|
|
}
|
|
|
|
|
|
|
|
func (notImplementedError) NotImplemented() {}
|
|
|
|
|
2016-11-16 20:58:06 -05:00
|
|
|
func experimentalHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
2017-07-19 10:20:13 -04:00
|
|
|
return notImplementedError{}
|
2016-11-16 20:58:06 -05:00
|
|
|
}
|
|
|
|
|
2018-08-31 11:27:02 -04:00
|
|
|
// Handler returns the APIFunc to let the server wrap it in middlewares.
|
2016-11-16 20:58:06 -05:00
|
|
|
func (r *experimentalRoute) Handler() httputils.APIFunc {
|
|
|
|
return r.handler
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method returns the http method that the route responds to.
|
|
|
|
func (r *experimentalRoute) Method() string {
|
|
|
|
return r.local.Method()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path returns the subpath where the route responds to.
|
|
|
|
func (r *experimentalRoute) Path() string {
|
|
|
|
return r.local.Path()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Experimental will mark a route as experimental.
|
|
|
|
func Experimental(r Route) Route {
|
|
|
|
return &experimentalRoute{
|
|
|
|
local: r,
|
|
|
|
handler: experimentalHandler,
|
|
|
|
}
|
|
|
|
}
|