diff --git a/octopus/outputadapter.go b/adapter/basicadapters.go similarity index 62% rename from octopus/outputadapter.go rename to adapter/basicadapters.go index 32980bc..598c542 100644 --- a/octopus/outputadapter.go +++ b/adapter/basicadapters.go @@ -1,28 +1,19 @@ -package octopus +package adapter import ( "fmt" "io" "log" "os" -) -// OutputAdapter is the interface for the Adapter that is used to handle -// output from the Octopus Crawler. -// The contract stipulates that the crawler provides the channel -// to listen for a quit command. -// The crawler pumps its output onto the returned channel of the Consume method. -// Implementers of the interface should listen on this channel for output from -// the crawler. -type OutputAdapter interface { - Consume(quitCh <-chan bool) chan<- CrawlOutput -} + oct "github.com/rapidclock/web-octopus/octopus" +) // StdOpAdapter is an output adapter that just prints the output onto the screen. type StdOpAdapter struct{} -func (s *StdOpAdapter) Consume(quitCh <-chan bool) chan<- CrawlOutput { - listenCh := make(chan CrawlOutput) +func (s *StdOpAdapter) Consume(quitCh <-chan bool) chan<- oct.CrawlOutput { + listenCh := make(chan oct.CrawlOutput) go func() { for { select { @@ -41,13 +32,13 @@ type FileWriterAdapter struct { FilePath string } -func (fw *FileWriterAdapter) Consume(quitCh <-chan bool) chan<- CrawlOutput { - listenCh := make(chan CrawlOutput) +func (fw *FileWriterAdapter) Consume(quitCh <-chan bool) chan<- oct.CrawlOutput { + listenCh := make(chan oct.CrawlOutput) fw.writeToFile(quitCh, listenCh) return listenCh } -func (fw *FileWriterAdapter) writeToFile(quitCh <-chan bool, ch <-chan CrawlOutput) { +func (fw *FileWriterAdapter) writeToFile(quitCh <-chan bool, ch <-chan oct.CrawlOutput) { fp, err := fw.getFilePointer() if err != nil { fp.Close() diff --git a/octopus/models.go b/octopus/models.go index 6103e4d..b1e4f50 100644 --- a/octopus/models.go +++ b/octopus/models.go @@ -46,3 +46,14 @@ type CrawlOutput struct { Node Body io.ReadCloser } + +// OutputAdapter is the interface for the Adapter that is used to handle +// output from the Octopus Crawler. +// The contract stipulates that the crawler provides the channel +// to listen for a quit command. +// The crawler pumps its output onto the returned channel of the Consume method. +// Implementers of the interface should listen on this channel for output from +// the crawler. +type OutputAdapter interface { + Consume(quitCh <-chan bool) chan<- CrawlOutput +}