Documentation
¶
Index ¶
- func ArrayDelete[T any](stack *[]T, pos int) (T, bool)
- func ArrayPop[T any](stack *[]T, count int) bool
- type Node
- func (n *Node) AddChild(k *Node) bool
- func (n *Node) Child(idx int) *Node
- func (n *Node) ChildByName(name string, recurse ...bool) *Node
- func (n *Node) Children() []*Node
- func (n *Node) DToMap() map[string]any
- func (n *Node) Data(data ...any) any
- func (n *Node) Depth() int
- func (n *Node) Destroy()
- func (n *Node) Detach() bool
- func (n *Node) Index() int
- func (n *Node) IsMapLike() bool
- func (n *Node) Len() int
- func (n *Node) MarshalJSON() ([]byte, error)
- func (n *Node) Name(name ...string) string
- func (n *Node) NewChild() *Node
- func (n *Node) NewChildWithData(d any) *Node
- func (n *Node) NewChildWithDataAndName(d any, name string) *Node
- func (n *Node) NewChildWithName(name string) *Node
- func (n *Node) NewChildWithNameAndData(name string, d any) *Node
- func (n *Node) Parent() *Node
- func (n *Node) RmAllChildren()
- func (n *Node) RmChild(idx int) bool
- func (n *Node) Root() *Node
- func (n *Node) ToMap() any
- func (n *Node) UnmarshalJSON(pay []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayDelete ¶
Delete an item from an array, returning item and true on success.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Recursive Node structure
func NewNodeWithDataAndName ¶
Alias for NewNodeWithNameAndData
Constructs a Node with a name and data
func NewNodeWithNameAndData ¶
Constructs a Node with a name and data
func (*Node) AddChild ¶
Adds a given node, only if the child isn't already a child
func (*Node) ChildByName ¶
Finds the child by name, if recurse then called recursively too
func (*Node) Children ¶
Obtain a list of children "child" nodes below this node
func (*Node) DToMap ¶
This forms a map to represent the node (it recursively is called on children)
This is the Debug version, it explicitly indicates Data, Name, Children (You most-likely want ToMap)
func (*Node) Data ¶
Obtain or Assign the data associated with this node
func (*Node) Depth ¶
Obtain the number of nodes above this one till reaching the "root" node
func (*Node) Index ¶
Obtains the index number for this node from the parent
Returns -1 to indicate error (either there is no parent or the parent doesn't have this node as a child)
func (*Node) IsMapLike ¶
Checks if the children of this node are better represented as a map or an array
This is determined by:
* Totaling number of children without names
* Comparing the percent of children without names to total children (if less than 50% use a map, if more than 50% use an array)
func (*Node) MarshalJSON ¶
Marshals the results from ToMap
func (*Node) Name ¶
Obtain or Assign the name associated with this node
Used for parsing JSON (this is the field name)
func (*Node) NewChildWithData ¶
Creates a new child node with data below this node
func (*Node) NewChildWithDataAndName ¶
Alias function of NewChildWithNameAndData
Creates a new child node with a name and data below with this node
func (*Node) NewChildWithName ¶
Creates a new child node with a name below this node
func (*Node) NewChildWithNameAndData ¶
Creates a new child node with a name and data below this node
func (*Node) Parent ¶
Obtain the parent of this node
Returning nil for the "root" node (as there is no parent)
func (*Node) RmChild ¶
Removes the child from this node by index
func (*Node) Root ¶
Obtain the top-most "root" node
It may include this node if this node is in fact "root"
func (*Node) ToMap ¶
Forms a minimal map to represent this node (and is recursively called on children)
Unlike DToMap, this version doesn't explicitly state the fields