Exemple #1
0
// respToLongOuput formats an etcd response for output in the long format.
func (h *LsHandler) respToLongOutput(resp *etcd.Response) string {
	output := bytes.NewBufferString("")
	widths := columnWidths(resp.Node)
	node := etcd.Node{
		Dir:           true,
		Key:           ".",
		CreatedIndex:  0,
		ModifiedIndex: 0,
	}
	output.WriteString(h.formatNodeLong(&node, widths))
	node.Key = ".."
	output.WriteString(h.formatNodeLong(&node, widths))

	total := 2
	for _, node := range resp.Node.Nodes {
		output.WriteString(h.formatNodeLong(node, widths))
		total++
		for _, n := range node.Nodes {
			output.WriteString(h.formatNodeLong(n, widths))
			total++
		}
	}

	return fmt.Sprintf("total %d\n%s", total, output.String())
}
Exemple #2
0
func (watch *Watch) sendNodesRecursively(node *goetcd.Node) uint64 {
	if !node.Dir {
		// Send this to channel if it is not a repeat.
		if node.ModifiedIndex > watch.sentIndex {
			log.Println("Watch etcd.Watch sendNodes sending ", node)
			node.Key = strings.TrimPrefix(node.Key, watch.prefix+"/")
			watch.C <- node
		}
		return node.ModifiedIndex
	}

	index := node.ModifiedIndex
	for _, node := range node.Nodes {
		// Iterate into directory, track largest index we've seen.
		if i := watch.sendNodesRecursively(node); i > index {
			index = i
		}
	}
	return index
}