github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/api/server/router/local.go (about)

     1  package router // import "github.com/docker/docker/api/server/router"
     2  
     3  import (
     4  	"github.com/docker/docker/api/server/httputils"
     5  )
     6  
     7  // RouteWrapper wraps a route with extra functionality.
     8  // It is passed in when creating a new route.
     9  type RouteWrapper func(r Route) Route
    10  
    11  // localRoute defines an individual API route to connect
    12  // with the docker daemon. It implements Route.
    13  type localRoute struct {
    14  	method  string
    15  	path    string
    16  	handler httputils.APIFunc
    17  }
    18  
    19  // Handler returns the APIFunc to let the server wrap it in middlewares.
    20  func (l localRoute) Handler() httputils.APIFunc {
    21  	return l.handler
    22  }
    23  
    24  // Method returns the http method that the route responds to.
    25  func (l localRoute) Method() string {
    26  	return l.method
    27  }
    28  
    29  // Path returns the subpath where the route responds to.
    30  func (l localRoute) Path() string {
    31  	return l.path
    32  }
    33  
    34  // NewRoute initializes a new local route for the router.
    35  func NewRoute(method, path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    36  	var r Route = localRoute{method, path, handler}
    37  	for _, o := range opts {
    38  		r = o(r)
    39  	}
    40  	return r
    41  }
    42  
    43  // NewGetRoute initializes a new route with the http method GET.
    44  func NewGetRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    45  	return NewRoute("GET", path, handler, opts...)
    46  }
    47  
    48  // NewPostRoute initializes a new route with the http method POST.
    49  func NewPostRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    50  	return NewRoute("POST", path, handler, opts...)
    51  }
    52  
    53  // NewPutRoute initializes a new route with the http method PUT.
    54  func NewPutRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    55  	return NewRoute("PUT", path, handler, opts...)
    56  }
    57  
    58  // NewDeleteRoute initializes a new route with the http method DELETE.
    59  func NewDeleteRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    60  	return NewRoute("DELETE", path, handler, opts...)
    61  }
    62  
    63  // NewOptionsRoute initializes a new route with the http method OPTIONS.
    64  func NewOptionsRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    65  	return NewRoute("OPTIONS", path, handler, opts...)
    66  }
    67  
    68  // NewHeadRoute initializes a new route with the http method HEAD.
    69  func NewHeadRoute(path string, handler httputils.APIFunc, opts ...RouteWrapper) Route {
    70  	return NewRoute("HEAD", path, handler, opts...)
    71  }