From bd214227dc6189e44d4b32c62d51f36f2ea4e036 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 21 Dec 2017 19:30:01 +0000 Subject: [PATCH] introduce ParsePseudoNodeID unused for now A convenient place to document and deal with the ugliness. --- render/id.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/render/id.go b/render/id.go index 25ba459f9..97f5f5b9f 100644 --- a/render/id.go +++ b/render/id.go @@ -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}, ":")