|
|
@ -72,19 +72,24 @@ func (n *Node) HardwareType() HardwareType {
|
|
|
|
return ht
|
|
|
|
return ht
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Values from json root
|
|
|
|
|
|
|
|
func (n *Node) Values() ([]Value, error) {
|
|
|
|
|
|
|
|
ret := []Value{}
|
|
|
|
|
|
|
|
err := n.Walk(func(val Value) error {
|
|
|
|
|
|
|
|
ret = append(ret, val)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Walk from json root
|
|
|
|
// Walk from json root
|
|
|
|
func (n *Node) Walk(fn Visitor) error {
|
|
|
|
func (n *Node) Walk(fn Visitor) error {
|
|
|
|
return n.walk(fn, Value{Hardware: []Hardware{}}, 0, 0)
|
|
|
|
return n.walk(fn, Value{Hardware: []Hardware{}}, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (n *Node) childDeviceTotals() map[HardwareType]int {
|
|
|
|
|
|
|
|
totals := map[HardwareType]int{}
|
|
|
|
|
|
|
|
for _, child := range n.Children {
|
|
|
|
|
|
|
|
totals[child.HardwareType()]++
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return totals
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (n *Node) walk(fn Visitor, ctx Value, hwIndex, hwTotal int) error {
|
|
|
|
func (n *Node) walk(fn Visitor, ctx Value, hwIndex, hwTotal int) error {
|
|
|
|
if n.IsValue() {
|
|
|
|
if n.IsValue() {
|
|
|
|
ctx.Label = n.Text
|
|
|
|
ctx.Label = n.Text
|
|
|
@ -115,17 +120,12 @@ func (n *Node) walk(fn Visitor, ctx Value, hwIndex, hwTotal int) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Values from json root
|
|
|
|
func (n *Node) childDeviceTotals() map[HardwareType]int {
|
|
|
|
func (n *Node) Values() ([]Value, error) {
|
|
|
|
totals := map[HardwareType]int{}
|
|
|
|
ret := []Value{}
|
|
|
|
for _, child := range n.Children {
|
|
|
|
err := n.Walk(func(val Value) error {
|
|
|
|
totals[child.HardwareType()]++
|
|
|
|
ret = append(ret, val)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
return totals
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Stringify tree
|
|
|
|
// Stringify tree
|
|
|
|