traefik/pkg/config/parser/labels_encode.go

31 lines
614 B
Go
Raw Normal View History

package parser
2018-12-04 13:24:04 +00:00
// EncodeNode Converts a node to labels.
2020-05-11 10:06:07 +00:00
// nodes -> labels.
2018-12-04 13:24:04 +00:00
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
}
var sep string
if child.Name[0] != '[' {
sep = "."
}
childName := root + sep + child.Name
2018-12-04 13:24:04 +00:00
if len(child.Children) > 0 {
encodeNode(labels, childName, child)
} else if len(child.Name) > 0 {
labels[childName] = child.Value
}
}
}