Add crawler skeleton and add handler
This commit is contained in:
34
internal/crawler.go
Normal file
34
internal/crawler.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Crawler interface {
|
||||
Start()
|
||||
Crawl(url string) error
|
||||
}
|
||||
|
||||
type crawler struct {
|
||||
q chan string
|
||||
}
|
||||
|
||||
func NewCrawler() (Crawler, error) {
|
||||
return &crawler{q: make(chan string)}, nil
|
||||
}
|
||||
|
||||
func (c *crawler) loop() {
|
||||
for {
|
||||
url := <-c.q
|
||||
log.Debugf("crawling %s", url)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *crawler) Crawl(url string) error {
|
||||
c.q <- url
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *crawler) Start() {
|
||||
go c.loop()
|
||||
}
|
||||
Reference in New Issue
Block a user