Files
spyda/internal/crawler.go
2021-02-01 21:25:32 +10:00

35 lines
452 B
Go

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()
}