|
|
|
@ -72,19 +72,24 @@ func (n *Node) HardwareType() HardwareType {
|
|
|
|
|
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
|
|
|
|
|
func (n *Node) Walk(fn Visitor) error {
|
|
|
|
|
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 {
|
|
|
|
|
if n.IsValue() {
|
|
|
|
|
ctx.Label = n.Text
|
|
|
|
@ -115,17 +120,12 @@ func (n *Node) walk(fn Visitor, ctx Value, hwIndex, hwTotal int) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
func (n *Node) childDeviceTotals() map[HardwareType]int {
|
|
|
|
|
totals := map[HardwareType]int{}
|
|
|
|
|
for _, child := range n.Children {
|
|
|
|
|
totals[child.HardwareType()]++
|
|
|
|
|
}
|
|
|
|
|
return ret, nil
|
|
|
|
|
return totals
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stringify tree
|
|
|
|
|