From b1f316ffc76af891b0aa37d66cbbe1814eb35c14 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 8 Sep 2015 11:50:18 +0200 Subject: [PATCH] =?UTF-8?q?Add=20Prune=20method=20(n=C3=A9e=20Sterilize)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render/renderable_node.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/render/renderable_node.go b/render/renderable_node.go index cf3917fe5..591ede43d 100644 --- a/render/renderable_node.go +++ b/render/renderable_node.go @@ -122,6 +122,17 @@ func (rn RenderableNode) Copy() RenderableNode { } } +// Prune returns a copy of the RenderableNode with all information not +// strictly necessary for rendering nodes and edges stripped away. +// Specifically, that means cutting out parts of the Node. +func (rn RenderableNode) Prune() RenderableNode { + cp := rn.Copy() + cp.Node.Metadata = report.Metadata{} // snip + cp.Node.Counters = report.Counters{} // snip + cp.Node.Edges = report.EdgeMetadatas{} // snip + return cp +} + // RenderableNodes is a set of RenderableNodes type RenderableNodes map[string]RenderableNode @@ -149,3 +160,13 @@ func (rns RenderableNodes) Merge(other RenderableNodes) RenderableNodes { } return result } + +// Prune returns a copy of the RenderableNodes with all information not +// strictly necessary for rendering nodes and edges in the UI cut away. +func (rns RenderableNodes) Prune() RenderableNodes { + cp := rns.Copy() + for id, rn := range cp { + cp[id] = rn.Prune() + } + return cp +}