mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
CHORE: Fix golint warnings about stuttering (#2718)
This commit is contained in:
@@ -11,33 +11,33 @@ const (
|
|||||||
OutgoingEdge
|
OutgoingEdge
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSGraphEdge an edge on the graph.
|
// Edge an edge on the graph.
|
||||||
type DNSGraphEdge[T Graphable] struct {
|
type Edge[T Graphable] struct {
|
||||||
Dependency Dependency
|
Dependency Dependency
|
||||||
Node *DNSGraphNode[T]
|
Node *Node[T]
|
||||||
Direction edgeDirection
|
Direction edgeDirection
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNSGraphEdges a list of edges.
|
// Edges a list of edges.
|
||||||
type DNSGraphEdges[T Graphable] []DNSGraphEdge[T]
|
type Edges[T Graphable] []Edge[T]
|
||||||
|
|
||||||
// DNSGraphNode a node in the graph.
|
// Node a node in the graph.
|
||||||
type DNSGraphNode[T Graphable] struct {
|
type Node[T Graphable] struct {
|
||||||
Data T
|
Data T
|
||||||
Edges DNSGraphEdges[T]
|
Edges Edges[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
type dnsGraphNodes[T Graphable] []*DNSGraphNode[T]
|
type dnsGraphNodes[T Graphable] []*Node[T]
|
||||||
|
|
||||||
// DNSGraph a graph.
|
// Graph a graph.
|
||||||
type DNSGraph[T Graphable] struct {
|
type Graph[T Graphable] struct {
|
||||||
All dnsGraphNodes[T]
|
All dnsGraphNodes[T]
|
||||||
Tree *dnstree.DomainTree[dnsGraphNodes[T]]
|
Tree *dnstree.DomainTree[dnsGraphNodes[T]]
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGraph returns a graph.
|
// CreateGraph returns a graph.
|
||||||
func CreateGraph[T Graphable](entries []T) *DNSGraph[T] {
|
func CreateGraph[T Graphable](entries []T) *Graph[T] {
|
||||||
graph := &DNSGraph[T]{
|
graph := &Graph[T]{
|
||||||
All: dnsGraphNodes[T]{},
|
All: dnsGraphNodes[T]{},
|
||||||
Tree: dnstree.Create[dnsGraphNodes[T]](),
|
Tree: dnstree.Create[dnsGraphNodes[T]](),
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ func CreateGraph[T Graphable](entries []T) *DNSGraph[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveNode removes a node from a graph.
|
// RemoveNode removes a node from a graph.
|
||||||
func (graph *DNSGraph[T]) RemoveNode(toRemove *DNSGraphNode[T]) {
|
func (graph *Graph[T]) RemoveNode(toRemove *Node[T]) {
|
||||||
for _, edge := range toRemove.Edges {
|
for _, edge := range toRemove.Edges {
|
||||||
edge.Node.Edges = edge.Node.Edges.RemoveNode(toRemove)
|
edge.Node.Edges = edge.Node.Edges.RemoveNode(toRemove)
|
||||||
}
|
}
|
||||||
@@ -71,11 +71,11 @@ func (graph *DNSGraph[T]) RemoveNode(toRemove *DNSGraphNode[T]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddNode adds a node to a graph.
|
// AddNode adds a node to a graph.
|
||||||
func (graph *DNSGraph[T]) AddNode(data T) {
|
func (graph *Graph[T]) AddNode(data T) {
|
||||||
nodes := graph.Tree.Get(data.GetName())
|
nodes := graph.Tree.Get(data.GetName())
|
||||||
node := &DNSGraphNode[T]{
|
node := &Node[T]{
|
||||||
Data: data,
|
Data: data,
|
||||||
Edges: DNSGraphEdges[T]{},
|
Edges: Edges[T]{},
|
||||||
}
|
}
|
||||||
if nodes == nil {
|
if nodes == nil {
|
||||||
nodes = dnsGraphNodes[T]{}
|
nodes = dnsGraphNodes[T]{}
|
||||||
@@ -87,7 +87,7 @@ func (graph *DNSGraph[T]) AddNode(data T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEdge adds an edge to a graph.
|
// AddEdge adds an edge to a graph.
|
||||||
func (graph *DNSGraph[T]) AddEdge(sourceNode *DNSGraphNode[T], dependency Dependency) {
|
func (graph *Graph[T]) AddEdge(sourceNode *Node[T], dependency Dependency) {
|
||||||
destinationNodes := graph.Tree.Get(dependency.NameFQDN)
|
destinationNodes := graph.Tree.Get(dependency.NameFQDN)
|
||||||
|
|
||||||
if destinationNodes == nil {
|
if destinationNodes == nil {
|
||||||
@@ -103,13 +103,13 @@ func (graph *DNSGraph[T]) AddEdge(sourceNode *DNSGraphNode[T], dependency Depend
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceNode.Edges = append(sourceNode.Edges, DNSGraphEdge[T]{
|
sourceNode.Edges = append(sourceNode.Edges, Edge[T]{
|
||||||
Dependency: dependency,
|
Dependency: dependency,
|
||||||
Node: destinationNode,
|
Node: destinationNode,
|
||||||
Direction: OutgoingEdge,
|
Direction: OutgoingEdge,
|
||||||
})
|
})
|
||||||
|
|
||||||
destinationNode.Edges = append(destinationNode.Edges, DNSGraphEdge[T]{
|
destinationNode.Edges = append(destinationNode.Edges, Edge[T]{
|
||||||
Dependency: dependency,
|
Dependency: dependency,
|
||||||
Node: sourceNode,
|
Node: sourceNode,
|
||||||
Direction: IncomingEdge,
|
Direction: IncomingEdge,
|
||||||
@@ -118,7 +118,7 @@ func (graph *DNSGraph[T]) AddEdge(sourceNode *DNSGraphNode[T], dependency Depend
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveNode removes a node from a graph.
|
// RemoveNode removes a node from a graph.
|
||||||
func (nodes dnsGraphNodes[T]) RemoveNode(toRemove *DNSGraphNode[T]) dnsGraphNodes[T] {
|
func (nodes dnsGraphNodes[T]) RemoveNode(toRemove *Node[T]) dnsGraphNodes[T] {
|
||||||
var newNodes dnsGraphNodes[T]
|
var newNodes dnsGraphNodes[T]
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@@ -131,8 +131,8 @@ func (nodes dnsGraphNodes[T]) RemoveNode(toRemove *DNSGraphNode[T]) dnsGraphNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveNode removes a node from a graph.
|
// RemoveNode removes a node from a graph.
|
||||||
func (edges DNSGraphEdges[T]) RemoveNode(toRemove *DNSGraphNode[T]) DNSGraphEdges[T] {
|
func (edges Edges[T]) RemoveNode(toRemove *Node[T]) Edges[T] {
|
||||||
var newEdges DNSGraphEdges[T]
|
var newEdges Edges[T]
|
||||||
|
|
||||||
for _, edge := range edges {
|
for _, edge := range edges {
|
||||||
if edge.Node != toRemove {
|
if edge.Node != toRemove {
|
||||||
@@ -144,7 +144,7 @@ func (edges DNSGraphEdges[T]) RemoveNode(toRemove *DNSGraphNode[T]) DNSGraphEdge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Contains returns true if a node is in the graph AND is in that direction.
|
// Contains returns true if a node is in the graph AND is in that direction.
|
||||||
func (edges DNSGraphEdges[T]) Contains(toFind *DNSGraphNode[T], direction edgeDirection) bool {
|
func (edges Edges[T]) Contains(toFind *Node[T], direction edgeDirection) bool {
|
||||||
|
|
||||||
for _, edge := range edges {
|
for _, edge := range edges {
|
||||||
if edge.Node == toFind && edge.Direction == direction {
|
if edge.Node == toFind && edge.Direction == direction {
|
||||||
|
@@ -49,7 +49,7 @@ func SortUsingGraph[T dnsgraph.Graphable](records []T) SortResult[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type directedSortState[T dnsgraph.Graphable] struct {
|
type directedSortState[T dnsgraph.Graphable] struct {
|
||||||
graph *dnsgraph.DNSGraph[T]
|
graph *dnsgraph.Graph[T]
|
||||||
sortedRecords []T
|
sortedRecords []T
|
||||||
unresolvedRecords []T
|
unresolvedRecords []T
|
||||||
hasResolvedLastRound bool
|
hasResolvedLastRound bool
|
||||||
@@ -106,7 +106,7 @@ func (sortState *directedSortState[T]) finalize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasUnmetDependencies[T dnsgraph.Graphable](node *dnsgraph.DNSGraphNode[T]) bool {
|
func hasUnmetDependencies[T dnsgraph.Graphable](node *dnsgraph.Node[T]) bool {
|
||||||
for _, edge := range node.Edges {
|
for _, edge := range node.Edges {
|
||||||
if edge.Dependency.Type == dnsgraph.BackwardDependency && edge.Direction == dnsgraph.IncomingEdge {
|
if edge.Dependency.Type == dnsgraph.BackwardDependency && edge.Direction == dnsgraph.IncomingEdge {
|
||||||
return true
|
return true
|
||||||
|
Reference in New Issue
Block a user