improve: NewHunter
This commit is contained in:
parent
ea6cfc1efa
commit
a0224e5842
19
hunter.go
19
hunter.go
|
@ -27,11 +27,24 @@ type Hunter struct {
|
||||||
createQueue func() *pqueue.PriorityQueue
|
createQueue func() *pqueue.PriorityQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHunter 默认最大优先
|
// NewHunter 默认最大优先, tasks为预先需要addtask
|
||||||
func NewHunter() *Hunter {
|
func NewHunter(tasks ...ITask) *Hunter {
|
||||||
return NewPriorityMaxHunter()
|
hunter := NewPriorityMaxHunter()
|
||||||
|
for _, task := range tasks {
|
||||||
|
hunter.AddTask(task)
|
||||||
|
}
|
||||||
|
return hunter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewHunterFromTasks 默认最大优先
|
||||||
|
// func NewHunterFromTasks(tasks ...ITask) *Hunter {
|
||||||
|
// hunter := NewPriorityMaxHunter()
|
||||||
|
// for _, task := range tasks {
|
||||||
|
// hunter.AddTask(task)
|
||||||
|
// }
|
||||||
|
// return hunter
|
||||||
|
// }
|
||||||
|
|
||||||
// NewPriorityHunter 自定义优先处理队列
|
// NewPriorityHunter 自定义优先处理队列
|
||||||
func NewPriorityHunter(queueCreator func() *pqueue.PriorityQueue) *Hunter {
|
func NewPriorityHunter(queueCreator func() *pqueue.PriorityQueue) *Hunter {
|
||||||
hunter := &Hunter{}
|
hunter := &Hunter{}
|
||||||
|
|
|
@ -19,12 +19,10 @@ func (web *WebGurl) Execute(cxt *TaskContext) {
|
||||||
|
|
||||||
func TestCurlCom(t *testing.T) {
|
func TestCurlCom(t *testing.T) {
|
||||||
curlBash := "curl 'http://httpbin.org/' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' --compressed --insecure"
|
curlBash := "curl 'http://httpbin.org/' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' --compressed --insecure"
|
||||||
hunter := NewHunter()
|
hunter := NewHunter(&WebGurl{PreCurlUrl(curlBash)}) // first params PreCurlUrl
|
||||||
hunter.AddTask(&WebGurl{PreCurlUrl: PreCurlUrl(curlBash)})
|
|
||||||
hunter.Execute()
|
hunter.Execute()
|
||||||
|
|
||||||
content := hunter.GetShare("test").(string)
|
content := hunter.GetShare("test").(string)
|
||||||
|
|
||||||
isMatchContent := regexp.MustCompile("<title>httpbin.org</title>").MatchString(content)
|
isMatchContent := regexp.MustCompile("<title>httpbin.org</title>").MatchString(content)
|
||||||
if !isMatchContent {
|
if !isMatchContent {
|
||||||
t.Error(content)
|
t.Error(content)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user