// NewRouter initializes a new network router func NewRouter(d *daemon.Daemon) router.Router { c := d.NetworkController() if c == nil { return networkRouter{} } var routes []router.Route netHandler := api.NewHTTPHandler(c) // TODO: libnetwork should stop hijacking request/response. // It should define API functions to add normally to the router. handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { netHandler(w, r) return nil } for _, path := range []string{"/networks", "/services", "/sandboxes"} { routes = append(routes, networkRoute{path, handler}) } return networkRouter{routes} }