-
Notifications
You must be signed in to change notification settings - Fork 1
/
topology.go
executable file
·66 lines (51 loc) · 1.13 KB
/
topology.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package streams
var _ Node = (*node)(nil)
type node struct {
name string
children []Node
}
// NewNode is a constructor for a new node in the topology.
func NewNode(name string) Node {
n := new(node)
n.name = name
return n
}
// AddChild adds a child to a node.
func (n *node) AddChild(child Node) {
n.children = append(n.children, child)
}
// Children returns the children of a node.
func (n *node) Children() []Node {
return n.children
}
// Name returns the name of a node.
func (n *node) Name() string {
return n.name
}
// Topology is a graph of nodes.
type Topology interface {
// Root returns the root node of a topology.
Root() Node
}
// Node is a node in a topology.
type Node interface {
// AddChild adds a child to a node.
AddChild(Node)
// Children returns the children of a node.
Children() []Node
// Name returns the name of a node.
Name() string
}
type topology struct {
root Node
}
// NewTopology is a constructor for Topology.
func NewTopology(root Node) Topology {
t := new(topology)
t.root = root
return t
}
// Root returns the root node of a topology.
func (t *topology) Root() Node {
return t.root
}