introduce ParsePseudoNodeID

unused for now

A convenient place to document and deal with the ugliness.
This commit is contained in:
Matthias Radestock
2017-12-21 19:30:01 +00:00
parent 0cb34b53cc
commit bd214227dc

View File

@@ -23,6 +23,20 @@ func MakePseudoNodeID(parts ...string) string {
return strings.Join(append([]string{"pseudo"}, parts...), ":")
}
// ParsePseudoNodeID returns the joined id parts of a pseudonode
// ID. If the ID is not recognisable as a pseudonode ID, it is
// returned as is, with the returned bool set to false. That is
// convenient because not all pseudonode IDs actually follow the
// format produced by MakePseudoNodeID.
func ParsePseudoNodeID(nodeID string) (string, bool) {
// Not using strings.SplitN() to avoid a heap allocation
pos := strings.Index(nodeID, ":")
if pos == -1 || nodeID[:pos] != "pseudo" {
return nodeID, false
}
return nodeID[pos+1:], true
}
// MakeGroupNodeTopology joins the parts of a group topology into the topology of a group node
func MakeGroupNodeTopology(originalTopology, key string) string {
return strings.Join([]string{"group", originalTopology, key}, ":")