hunter/context.go

44 lines
992 B
Go
Raw Normal View History

2020-04-07 10:55:41 +00:00
package hunter
// TaskContext 上下文
type TaskContext struct {
2020-04-07 17:18:33 +00:00
share map[string]interface{}
2020-04-07 10:55:41 +00:00
hunter *Hunter
curNode ITaskNode
}
// NewContext 任务上下文
func NewContext() *TaskContext {
return &TaskContext{}
}
// AddTask 添加到当前子任务队列
func (cxt *TaskContext) AddTask(itask ITask) {
if children := cxt.curNode.Children(); children == nil {
cxt.curNode.SetChildren(cxt.hunter.createQueue())
}
2020-04-07 17:18:33 +00:00
bt := &BaseTask{}
bt.SetTask(itask)
cxt.curNode.Children().Push(bt)
2020-04-07 10:55:41 +00:00
}
// AddParentTask 添加到当前任务队列
func (cxt *TaskContext) AddParentTask(itask ITask) {
2020-04-07 17:18:33 +00:00
bt := &BaseTask{}
bt.SetTask(itask)
cxt.curNode.Parent().Children().Push(bt)
}
// GetShare 获取share的数据, 存储用的
func (cxt *TaskContext) GetShare(key string) interface{} {
if v, ok := cxt.share[key]; ok {
return v
}
return nil
}
// SetShare 设置share的数据, 存储用的
func (cxt *TaskContext) SetShare(key string, value interface{}) {
cxt.share[key] = value
2020-04-07 10:55:41 +00:00
}