Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions octopus/outputadapter.go → adapter/basicadapters.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions octopus/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}