func filterTreeDescend(pathPrefix string, node *types.Container, distances map[string]int) { newContainers := []types.Container{} for _, c := range node.Containers { // this implicitly copies the struct nextPathPrefix := pathPrefix + c.Name + "/" if pathPrefixInDistances(nextPathPrefix, distances) { newContainers = append(newContainers, c) nc := &newContainers[len(newContainers)-1] nc.Expanded = true filterTreeDescend(nextPathPrefix, nc, distances) } } newConnections := []types.Connection{} for _, c := range node.Connections { if pathPrefixInDistances(pathPrefix+c.Name, distances) { newConnections = append(newConnections, c) } } node.Containers = newContainers node.Connections = newConnections }