Labels parser.

This commit is contained in:
Ludovic Fernandez 2018-12-04 14:24:04 +01:00 committed by Traefiker Bot
parent 92f8e5cd3f
commit 11a0078966
16 changed files with 4462 additions and 4 deletions

View file

@ -0,0 +1,24 @@
package internal
// EncodeNode Converts a node to labels.
// nodes -> labels
func EncodeNode(node *Node) map[string]string {
labels := make(map[string]string)
encodeNode(labels, node.Name, node)
return labels
}
func encodeNode(labels map[string]string, root string, node *Node) {
for _, child := range node.Children {
if child.Disabled {
continue
}
childName := root + "." + child.Name
if len(child.Children) > 0 {
encodeNode(labels, childName, child)
} else if len(child.Name) > 0 {
labels[childName] = child.Value
}
}
}