Documentation
¶
Index ¶
- type ContextNode
- func (that *ContextNode) AddListener(listener MessageCallback) (listenerID string)
- func (that *ContextNode) Cancel()
- func (that *ContextNode) Children() []*ContextNode
- func (that *ContextNode) Context() context.Context
- func (that *ContextNode) FindAllNodesByName(name string) []struct{ ... }
- func (that *ContextNode) FindNodeByID(id string) (*ContextNode, []string)
- func (that *ContextNode) FindNodeByName(name string, parentID string) (*ContextNode, []string)
- func (that *ContextNode) GetPath() []string
- func (that *ContextNode) GetPathWithIDs() []string
- func (that *ContextNode) ID() string
- func (that *ContextNode) Name() string
- func (that *ContextNode) NewChild(name string) *ContextNode
- func (that *ContextNode) NewChildWithTag(name string, tag interface{}) *ContextNode
- func (that *ContextNode) Notify(source *ContextNode, msg interface{})
- func (that *ContextNode) Parent() *ContextNode
- func (that *ContextNode) Remove()
- func (that *ContextNode) RemoveListener(listenerID string)
- func (that *ContextNode) Root() *ContextNode
- func (that *ContextNode) SetTag(tag interface{})
- func (that *ContextNode) String() string
- func (that *ContextNode) Tag() interface{}
- type ContextTree
- type MessageCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextNode ¶
type ContextNode struct {
// contains filtered or unexported fields
}
Node 代表树状结构中的一个节点,封装context、cancel函数、名称和唯一ID 提供显式的父子关系管理,防止内存泄露,支持并发安全操作和重名场景查询
func (*ContextNode) AddListener ¶
func (that *ContextNode) AddListener(listener MessageCallback) (listenerID string)
AddListener 添加监听器,返回唯一监听器ID
func (*ContextNode) Cancel ¶
func (that *ContextNode) Cancel()
Cancel 取消当前节点及其子节点的context 与原生context的cancel等价,子context自动收到Done信号
func (*ContextNode) Children ¶
func (that *ContextNode) Children() []*ContextNode
GetChildren 返回当前节点的子节点列表(只读)
func (*ContextNode) Context ¶
func (that *ContextNode) Context() context.Context
Context 返回节点的context
func (*ContextNode) FindAllNodesByName ¶
func (that *ContextNode) FindAllNodesByName(name string) []struct { Node *ContextNode Path []string }
FindAllNodesByName 使用DFS查找所有匹配名称的节点 返回节点及其路径的列表,若无匹配返回空列表
func (*ContextNode) FindNodeByID ¶
func (that *ContextNode) FindNodeByID(id string) (*ContextNode, []string)
FindNodeByID 使用DFS查找匹配ID的节点 ID唯一,直接返回节点及其路径,若未找到返回nil
func (*ContextNode) FindNodeByName ¶
func (that *ContextNode) FindNodeByName(name string, parentID string) (*ContextNode, []string)
FindNodeByName 使用DFS查找第一个匹配名称的节点 可选parentID约束查找范围,返回节点及其路径,若未找到返回nil
func (*ContextNode) GetPath ¶
func (that *ContextNode) GetPath() []string
GetPath 返回节点从根到自身的路径(名称列表)
func (*ContextNode) GetPathWithIDs ¶
func (that *ContextNode) GetPathWithIDs() []string
GetPathWithIDs 返回节点从根到自身的路径(ID列表)
func (*ContextNode) NewChild ¶
func (that *ContextNode) NewChild(name string) *ContextNode
AddChild 为父节点添加子节点 自动创建子context并维护父子关系,生成唯一ID,线程安全
func (*ContextNode) NewChildWithTag ¶
func (that *ContextNode) NewChildWithTag(name string, tag interface{}) *ContextNode
AddChild 为父节点添加子节点 自动创建子context并维护父子关系,生成唯一ID,线程安全
func (*ContextNode) Notify ¶
func (that *ContextNode) Notify(source *ContextNode, msg interface{})
Notify 异步通知所有监听器
func (*ContextNode) Parent ¶
func (that *ContextNode) Parent() *ContextNode
GetParent 返回当前节点的父节点 如果是根节点,返回nil,线程安全
func (*ContextNode) RemoveListener ¶
func (that *ContextNode) RemoveListener(listenerID string)
RemoveListener 移除指定监听器
func (*ContextNode) Root ¶
func (that *ContextNode) Root() *ContextNode
GetRoot 返回树的根节点 通过递归向上遍历,线程安全
func (*ContextNode) SetTag ¶
func (that *ContextNode) SetTag(tag interface{})
SetTag 设置节点的tag值 支持任意类型,线程安全
func (*ContextNode) String ¶
func (that *ContextNode) String() string
String 返回以当前节点为根的子树的JSON表示 仅包含id、name和children字段,格式化输出,线程安全
func (*ContextNode) Tag ¶
func (that *ContextNode) Tag() interface{}
GetTag 获取节点的tag值 返回nil如果未设置,线程安全
type ContextTree ¶
type ContextTree struct {
// contains filtered or unexported fields
}
ContextManager 管理整个上下文树,提供统一入口
func NewContextTree ¶
func NewContextTree(rootName string) *ContextTree
NewContextManager 创建新的上下文管理器 相比原生context,提供显式树结构、资源清理和名称/ID查询功能
type MessageCallback ¶
type MessageCallback func(source *ContextNode, msg interface{})