-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue.go
55 lines (45 loc) · 1.05 KB
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package chuper
import (
"net/url"
"github.com/PuerkitoBio/fetchbot"
)
type Queue struct {
*fetchbot.Queue
}
type Enqueuer interface {
Enqueue(string, string, string, int) error
EnqueueWithBasicAuth(string, string, string, int, string, string) error
}
func (q *Queue) Enqueue(method, URL, sourceURL string, depth int) error {
u, err := url.Parse(URL)
if err != nil {
return err
}
s, err := url.Parse(sourceURL)
if err != nil {
return err
}
cmd := &Cmd{&fetchbot.Cmd{U: u, M: method}, s, depth}
if err = q.Send(cmd); err != nil {
return err
}
return nil
}
func (q *Queue) EnqueueWithBasicAuth(method string, URL string, sourceURL string, depth int, user string, password string) error {
if user == "" && password == "" {
return q.Enqueue(method, URL, sourceURL, depth)
}
u, err := url.Parse(URL)
if err != nil {
return err
}
s, err := url.Parse(sourceURL)
if err != nil {
return err
}
cmd := &CmdBasicAuth{&fetchbot.Cmd{U: u, M: method}, s, depth, user, password}
if err = q.Send(cmd); err != nil {
return err
}
return nil
}