Skip to content

Instantly share code, notes, and snippets.

@kanzitelli
Last active September 6, 2019 17:05
Show Gist options
  • Save kanzitelli/a49050c46c52cad0c0631b8345fbd8f5 to your computer and use it in GitHub Desktop.
Save kanzitelli/a49050c46c52cad0c0631b8345fbd8f5 to your computer and use it in GitHub Desktop.
crawler/crawler.go #1
package crawler
import (
"time"
)
// NewsCrawler <interface>
// is used to describe news crawler class instance
type NewsCrawler interface {
Run() []models.News
}
// NewsFunc <type>
// is used to simplify news func type signature
type NewsFunc func() []models.News
// Start <function>
// is used to start process of web resources crawling every 3 minutes
func Start() {
go startCrawler()
}
func startCrawler() {
// array of crawlers for different news sources which implement NewsCrawler interface.
crawlers := []NewsCrawler{
SecretMag{},
TheoryAndPractice{},
TheVillage{},
}
// duration of each crawling process
duration := time.Minute * 3
for range time.Tick(duration) {
// all news collected from each crawler
var totalNews []models.News
for _, cr := range crawlers {
totalNews = append(totalNews, cr.Run()...)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment