Add crawler skeleton and add handler

This commit is contained in:
James Mills
2021-02-01 21:23:58 +10:00
parent 8c84ee8b3d
commit b69b27eeed
6 changed files with 148 additions and 13 deletions

34
internal/crawler.go Normal file
View 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()
}