Documentation
¶
Index ¶
- type MetaData
- type Node
- type SubordinatesCount
- type SubordinatesInfo
- type SubordinatesResponse
- type Tree
- func (tree Tree) AttachNode(newNode *Node, parent *Node) error
- func (tree Tree) DetachNode(node *Node) (*Node, error)
- func (tree Tree) FindNode(id string, start *Node) (*Node, error)
- func (tree Tree) GetRoot() (*Node, error)
- func (tree Tree) MoveNode(node *Node, newParent *Node) error
- func (tree Tree) ToJSON() (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { ID string `json:"id"` Children []*Node `json:"children,omitempty"` Height int `json:"height,omitempty"` Data MetaData `json:"metadata,omitempty"` ParentID string `json:"parentId,omitempty"` RootID *string `json:"rootId,omitempty"` }
Node is the entity that is the building block of a tree it may or may not contain a `parentId`, that points to another node ID
func (*Node) GetDescendants ¶
func (node *Node) GetDescendants() SubordinatesResponse
GetDescendants returns a count and a hierarchy of the subtree (excluding the current node)
type SubordinatesCount ¶
SubordinatesCount contains a `direct` and a `total` count of subordinates
type SubordinatesInfo ¶
type SubordinatesInfo struct { Count SubordinatesCount `json:"count"` Hierarchy []*Node `json:"hierarchy,omitempty"` }
SubordinatesInfo contains a `count` of subordinates and a full `hierarchy` of nodes
type SubordinatesResponse ¶
type SubordinatesResponse struct {
Subordinates SubordinatesInfo `json:"subordinates"`
}
SubordinatesResponse is the base response for the GET subordinates route
type Tree ¶
Tree is the basic struct for any tree hierarchy
func FromJSON ¶
FromJSON receives JSON data for a tree and returns the unmarshalled struct of a Tree
func (Tree) AttachNode ¶
AttachNode will receive two node pointers in a tree, and will attach the first one as a subordinate of the foremost this will update the entire subtree of the node being attached
func (Tree) DetachNode ¶
DetachNode will remove a `node` from its parent and will return a pointer to the detached node
func (Tree) FindNode ¶
FindNode will find a node with `id` in the tree in O(n) operations by default, `start` node will be the Root node it is possible to define the `start` node to speed up operations