Key returns the children nodes making the Key on a supported node. Panics otherwise. They are guaranteed to be all be of the Kind Key. A simple key would return just one element.
()
| 97 | // otherwise. They are guaranteed to be all be of the Kind Key. A simple key |
| 98 | // would return just one element. |
| 99 | func (n *Node) Key() Iterator { |
| 100 | switch n.Kind { |
| 101 | case KeyValue: |
| 102 | value := n.Child() |
| 103 | if !value.Valid() { |
| 104 | panic(errors.New("KeyValue should have at least two children")) |
| 105 | } |
| 106 | return Iterator{node: value.Next()} |
| 107 | case Table, ArrayTable: |
| 108 | return Iterator{node: n.Child()} |
| 109 | default: |
| 110 | panic(fmt.Errorf("Key() is not supported on a %s", n.Kind)) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Value returns a pointer to the value node of a KeyValue. |
| 115 | // Guaranteed to be non-nil. Panics if not called on a KeyValue node, |