Skip to content

Commit d787233

Browse files
authored
Merge pull request #1 from rapidclock/#9nkcy-move-adapters
moved output adapters to separate package #9nkcy
2 parents 62b9f16 + 34afa26 commit d787233

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
package octopus
1+
package adapter
22

33
import (
44
"fmt"
55
"io"
66
"log"
77
"os"
8-
)
98

10-
// OutputAdapter is the interface for the Adapter that is used to handle
11-
// output from the Octopus Crawler.
12-
// The contract stipulates that the crawler provides the channel
13-
// to listen for a quit command.
14-
// The crawler pumps its output onto the returned channel of the Consume method.
15-
// Implementers of the interface should listen on this channel for output from
16-
// the crawler.
17-
type OutputAdapter interface {
18-
Consume(quitCh <-chan bool) chan<- CrawlOutput
19-
}
9+
oct "github.com/rapidclock/web-octopus/octopus"
10+
)
2011

2112
// StdOpAdapter is an output adapter that just prints the output onto the screen.
2213
type StdOpAdapter struct{}
2314

24-
func (s *StdOpAdapter) Consume(quitCh <-chan bool) chan<- CrawlOutput {
25-
listenCh := make(chan CrawlOutput)
15+
func (s *StdOpAdapter) Consume(quitCh <-chan bool) chan<- oct.CrawlOutput {
16+
listenCh := make(chan oct.CrawlOutput)
2617
go func() {
2718
for {
2819
select {
@@ -41,13 +32,13 @@ type FileWriterAdapter struct {
4132
FilePath string
4233
}
4334

44-
func (fw *FileWriterAdapter) Consume(quitCh <-chan bool) chan<- CrawlOutput {
45-
listenCh := make(chan CrawlOutput)
35+
func (fw *FileWriterAdapter) Consume(quitCh <-chan bool) chan<- oct.CrawlOutput {
36+
listenCh := make(chan oct.CrawlOutput)
4637
fw.writeToFile(quitCh, listenCh)
4738
return listenCh
4839
}
4940

50-
func (fw *FileWriterAdapter) writeToFile(quitCh <-chan bool, ch <-chan CrawlOutput) {
41+
func (fw *FileWriterAdapter) writeToFile(quitCh <-chan bool, ch <-chan oct.CrawlOutput) {
5142
fp, err := fw.getFilePointer()
5243
if err != nil {
5344
fp.Close()

octopus/models.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ type CrawlOutput struct {
4646
Node
4747
Body io.ReadCloser
4848
}
49+
50+
// OutputAdapter is the interface for the Adapter that is used to handle
51+
// output from the Octopus Crawler.
52+
// The contract stipulates that the crawler provides the channel
53+
// to listen for a quit command.
54+
// The crawler pumps its output onto the returned channel of the Consume method.
55+
// Implementers of the interface should listen on this channel for output from
56+
// the crawler.
57+
type OutputAdapter interface {
58+
Consume(quitCh <-chan bool) chan<- CrawlOutput
59+
}

0 commit comments

Comments
 (0)