refactor: better naming for MapEndpoints parameters

This commit is contained in:
Bryan Boreham
2019-10-23 18:35:23 +00:00
parent ce5d38d01e
commit ad9f8b6f1f
4 changed files with 14 additions and 14 deletions

View File

@@ -70,8 +70,8 @@ func (c connectionJoin) Render(ctx context.Context, rpt report.Report) Nodes {
}
}
return MapEndpoints(
func(m report.Node) string {
scope, addr, port, ok := report.ParseEndpointNodeID(m.ID)
func(endpoint report.Node) string {
scope, addr, port, ok := report.ParseEndpointNodeID(endpoint.ID)
if !ok {
return ""
}

View File

@@ -15,18 +15,18 @@ const Pseudo = "pseudo"
// EndpointRenderer is a Renderer which produces a renderable endpoint graph.
var EndpointRenderer = SelectEndpoint
type endpointMapFunc func(report.Node) string
type endpointToIDFunc func(report.Node) string
type mapEndpoints struct {
f endpointMapFunc
topology string
endpointToID endpointToIDFunc
topology string
}
// MapEndpoints creates a renderer for the endpoint topology. Each
// endpoint is either turned into a pseudo node, or mapped to a node
// in the specified topology by the supplied function.
func MapEndpoints(f endpointMapFunc, topology string) Renderer {
return mapEndpoints{f: f, topology: topology}
func MapEndpoints(endpointToID endpointToIDFunc, topology string) Renderer {
return mapEndpoints{endpointToID: endpointToID, topology: topology}
}
func (e mapEndpoints) Render(ctx context.Context, rpt report.Report) Nodes {
@@ -43,7 +43,7 @@ func (e mapEndpoints) Render(ctx context.Context, rpt report.Report) Nodes {
continue
}
}
if id := e.f(n); id != "" {
if id := e.endpointToID(n); id != "" {
ret.addChild(n, id, e.topology)
}
}

View File

@@ -50,8 +50,8 @@ func nodes2Hosts(nodes Nodes) Nodes {
return ret.result(nodes)
}
func endpoint2Host(n report.Node) string {
if hostNodeID, ok := n.Latest.Lookup(report.HostNodeID); ok {
func endpoint2Host(endpoint report.Node) string {
if hostNodeID, ok := endpoint.Latest.Lookup(report.HostNodeID); ok {
return hostNodeID
}
return ""

View File

@@ -49,15 +49,15 @@ func (e endpoints2Processes) Render(ctx context.Context, rpt report.Report) Node
}
endpoints := SelectEndpoint.Render(ctx, rpt).Nodes
return MapEndpoints(
func(n report.Node) string {
pid, ok := n.Latest.Lookup(report.PID)
func(endpoint report.Node) string {
pid, ok := endpoint.Latest.Lookup(report.PID)
if !ok {
return ""
}
if hasMoreThanOneConnection(n, endpoints) {
if hasMoreThanOneConnection(endpoint, endpoints) {
return ""
}
hostID := report.ExtractHostID(n)
hostID := report.ExtractHostID(endpoint)
if hostID == "" {
return ""
}