Created
September 7, 2019 22:49
-
-
Save kanzitelli/be4f82581ce43aaa061e229f36bf5998 to your computer and use it in GitHub Desktop.
Crawler/Crawler.go. #1
This file contains hidden or 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{}, | |
// other crawlers | |
} | |
// 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()...) | |
} | |
// next step: adding totalNews to db | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment