Skip to content

Commit c7c2d5e

Browse files
committed
redesign octopus v1
1 parent 8c66325 commit c7c2d5e

File tree

2 files changed

+11
-38
lines changed

2 files changed

+11
-38
lines changed

octopus/models.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ type NodeChSet struct {
6464
}
6565

6666
type StringChSet struct {
67-
strCh chan<- string
68-
*StdChannels
69-
}
70-
71-
type NodeInfoChSet struct {
72-
nodeInfoCh chan<- *NodeInfo
67+
StrCh chan<- string
7368
*StdChannels
7469
}
7570

octopus/pipe_htmlparsing.go

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,11 @@ import (
44
"golang.org/x/net/html"
55
)
66

7-
func (o *octopus) makeHtmlParsingPipe(outChSet *NodeInfoChSet) *NodeChSet {
8-
listenCh := make(chan *Node)
9-
listenQuitCh := make(chan int, 1)
10-
listenChSet := &NodeChSet{
11-
NodeCh: listenCh,
12-
StdChannels: &StdChannels{
13-
QuitCh: listenQuitCh,
14-
},
15-
}
16-
go func() {
17-
defer close(listenCh)
18-
defer close(listenQuitCh)
19-
for {
20-
select {
21-
case node := <-listenCh:
22-
{
23-
go parseHtmlPage(node, outChSet)
24-
}
25-
case <-listenQuitCh:
26-
{
27-
outChSet.QuitCh <- 1
28-
return
29-
}
30-
}
31-
}
32-
}()
33-
return listenChSet
7+
func (o *octopus) makeParseNodeFromHtmlPipe(outChSet *NodeChSet) *NodeChSet {
8+
return stdLinearNodeFunc(parseHtmlPage, outChSet)
349
}
3510

36-
func parseHtmlPage(node *Node, outChSet *NodeInfoChSet) {
11+
func parseHtmlPage(node *Node, outChSet *NodeChSet) {
3712
defer node.Body.Close()
3813
z := html.NewTokenizer(node.Body)
3914
for {
@@ -46,10 +21,13 @@ func parseHtmlPage(node *Node, outChSet *NodeInfoChSet) {
4621
if "a" == token.Data {
4722
for _, attr := range token.Attr {
4823
if attr.Key == "href" {
49-
outChSet.nodeInfoCh <- &NodeInfo{
50-
ParentUrlString: node.UrlString,
51-
UrlString: attr.Val,
52-
Depth: node.Depth + 1,
24+
outChSet.NodeCh <- &Node{
25+
NodeInfo: &NodeInfo{
26+
ParentUrlString: node.UrlString,
27+
UrlString: attr.Val,
28+
Depth: node.Depth + 1,
29+
},
30+
Body: nil,
5331
}
5432
}
5533
}

0 commit comments

Comments
 (0)