Last active
September 6, 2019 17:05
-
-
Save kanzitelli/a49050c46c52cad0c0631b8345fbd8f5 to your computer and use it in GitHub Desktop.
crawler/crawler.go #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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