mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6ad4bf0a53
When calling the /networks/ endpoint with a trailing slash, the default network was returned. This changes the endpoint to return the list of networks instead (same response as `/networks` without trailing slash). Also updated the description for GetNetworkByName to explain that the "default" network is returned if no name or id is provided. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package network
|
|
|
|
import (
|
|
"github.com/docker/docker/api/server/router"
|
|
"github.com/docker/docker/daemon/cluster"
|
|
)
|
|
|
|
// networkRouter is a router to talk with the network controller
|
|
type networkRouter struct {
|
|
backend Backend
|
|
clusterProvider *cluster.Cluster
|
|
routes []router.Route
|
|
}
|
|
|
|
// NewRouter initializes a new network router
|
|
func NewRouter(b Backend, c *cluster.Cluster) router.Router {
|
|
r := &networkRouter{
|
|
backend: b,
|
|
clusterProvider: c,
|
|
}
|
|
r.initRoutes()
|
|
return r
|
|
}
|
|
|
|
// Routes returns the available routes to the network controller
|
|
func (r *networkRouter) Routes() []router.Route {
|
|
return r.routes
|
|
}
|
|
|
|
func (r *networkRouter) initRoutes() {
|
|
r.routes = []router.Route{
|
|
// GET
|
|
router.NewGetRoute("/networks", r.getNetworksList),
|
|
router.NewGetRoute("/networks/", r.getNetworksList),
|
|
router.NewGetRoute("/networks/{id:.+}", r.getNetwork),
|
|
// POST
|
|
router.NewPostRoute("/networks/create", r.postNetworkCreate),
|
|
router.NewPostRoute("/networks/{id:.*}/connect", r.postNetworkConnect),
|
|
router.NewPostRoute("/networks/{id:.*}/disconnect", r.postNetworkDisconnect),
|
|
// DELETE
|
|
router.NewDeleteRoute("/networks/{id:.*}", r.deleteNetwork),
|
|
}
|
|
}
|