nodefactory

package module
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2021 License: MIT Imports: 9 Imported by: 0

README

nodefactory

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNode

type BaseNode struct {
	ID        string
	Name      string
	Children  map[Node]struct{}
	SyncMutex sync.Mutex
}

func (*BaseNode) AddChild

func (node *BaseNode) AddChild(child Node)

func (*BaseNode) GetChildren

func (node *BaseNode) GetChildren() map[Node]struct{}

func (*BaseNode) GetID

func (node *BaseNode) GetID() string

func (*BaseNode) GetName

func (node *BaseNode) GetName() string

func (*BaseNode) HasChild

func (node *BaseNode) HasChild(child Node) bool

func (*BaseNode) RemoveChild

func (node *BaseNode) RemoveChild(child Node)

func (*BaseNode) Send

func (node *BaseNode) Send(bytes []byte)

func (*BaseNode) ToJSON

func (node *BaseNode) ToJSON() ([]byte, error)

type MongoNode

type MongoNode struct {
	BaseNode
	Client *mongo.Client `json:"-"`
}

func CreateMongoNode

func CreateMongoNode(service string, ctx context.Context) (*MongoNode, error)

func (*MongoNode) Query

func (node *MongoNode) Query() ([]map[string]interface{}, error)

func (*MongoNode) Receive

func (node *MongoNode) Receive(bytes []byte) error

type Node

type Node interface {
	GetID() string
	GetName() string
	GetChildren() map[Node]struct{}
	Send([]byte)
	Receive([]byte) error
	AddChild(Node)
	RemoveChild(Node)
	HasChild(Node) bool
	ToJSON() ([]byte, error)
}

type Tree

type Tree struct {
	Nodes     map[string]Node
	SyncMutex *sync.Mutex
}

Tree is a flat structure that contains a map of nodes. The individual nodes are responsible for keeping track of their children.

func CreateTree

func CreateTree() *Tree

CreateTree creates a new instance of a tree.

func (*Tree) AddNode

func (tree *Tree) AddNode(node Node)

AddNode adds a node to the tree. This can be done concurrently.

func (*Tree) GetNodeByNameOrID

func (tree *Tree) GetNodeByNameOrID(nameOrID string) (Node, bool)

GetNodeByNameOrID returns node and if found. When searching by ID, the algorithm has O(1) time complexity. When searching by name, the algorithm has O(n) time complexity.

func (*Tree) IsEmpty

func (tree *Tree) IsEmpty() bool

IsEmpty checks if the tree contains zero nodes.

func (*Tree) IsNotEmpty

func (tree *Tree) IsNotEmpty() bool

IsNotEmpty checks if the tree contains at least one node.

func (*Tree) RemoveNode

func (tree *Tree) RemoveNode(node Node)

RemoveNode removes a node from the tree. This can be done concurrently.

func (*Tree) ToJSON

func (tree *Tree) ToJSON() ([]byte, error)

ToJSON converts the tree to sendable bytes. This is necessary as each node in the tree must also having its own ToJSON function that converts each child node of a particular node into an ID. This ID can then be used by the tree to lookup a particular node when sent to the client as JSON.

type WebsocketNode

type WebsocketNode struct {
	BaseNode
	Client *websocket.Conn `json:"-"`
}

func CreateWebsocketNode

func CreateWebsocketNode(url string, ctx context.Context) *WebsocketNode

func (*WebsocketNode) Activate

func (node *WebsocketNode) Activate(url string, ctx context.Context, wg *sync.WaitGroup)

func (*WebsocketNode) Receive

func (node *WebsocketNode) Receive(bytes []byte) error

func (*WebsocketNode) Start

func (node *WebsocketNode) Start(url string, ctx context.Context)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL