-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
63 lines (50 loc) · 1.03 KB
/
types.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
56
57
58
59
60
61
62
63
package engine
import "github.com/javahongxi/whatsgo/crawler/config"
type ParserFunc func(
contents []byte, url string) ParseResult
type Parser interface {
Parse(contents []byte, url string) ParseResult
Serialize() (name string, args interface{})
}
type Request struct {
Url string
Parser Parser
}
type ParseResult struct {
Requests []Request
Items []Item
}
type Item struct {
Url string
Type string
Id string
Payload interface{}
}
type NilParser struct{}
func (NilParser) Parse(
_ []byte, _ string) ParseResult {
return ParseResult{}
}
func (NilParser) Serialize() (
name string, args interface{}) {
return config.NilParser, nil
}
type FuncParser struct {
parser ParserFunc
name string
}
func (f *FuncParser) Parse(
contents []byte, url string) ParseResult {
return f.parser(contents, url)
}
func (f *FuncParser) Serialize() (
name string, args interface{}) {
return f.name, nil
}
func NewFuncParser(
p ParserFunc, name string) *FuncParser {
return &FuncParser{
parser: p,
name: name,
}
}