Example #1
0
func main() {
	config, err := OpenConfig("config.yml")
	if err != nil {
		logrus.WithError(err).Fatal("Error loading config file")
	}

	logrus.Info("Loaded config")

	repo, err := rethink.NewRepo(config.RethinkDB)
	if err != nil {
		logrus.WithError(err).Fatal("Error connecting to repository")
	}

	logrus.Info("Connected to repository")

	tokenValidator := controllers.NewTokenValidator(config.Token.ClientID)
	updateController := controllers.NewUpdateController(repo, tokenValidator)
	readController := controllers.NewReadController(repo, tokenValidator)
	readAllController := controllers.NewReadAllController(repo, tokenValidator)
	subscribeController := controllers.NewSubscribeController(repo, tokenValidator)
	unsubscribeController := controllers.NewUnsubscribeController(repo, tokenValidator)

	http.Handle("/updates", updateController)
	http.Handle("/read", readController)
	http.Handle("/readall", readAllController)
	http.Handle("/subscribe", subscribeController)
	http.Handle("/unsubscribe", unsubscribeController)

	logrus.Info("Starting server")
	http.ListenAndServe(config.Server.Listen, nil)
}
Example #2
0
func main() {
	config, err := OpenConfig("config.yml")
	if err != nil {
		logrus.WithError(err).Fatal("Error loading config file")
	}

	logrus.Info("Loaded config")

	repo, err := rethink.NewRepo(config.RethinkDB)
	if err != nil {
		logrus.WithError(err).Fatal("Error connecting to repository")
	}

	logrus.Info("Connected to repository")

	wp := blogalert.NewWorkerPool(runtime.NumCPU())
	extractor := blogalert.NewExtractor(repo, wp, logrus.StandardLogger())

	ticker := time.NewTicker(config.Refresh)
	logrus.Info("Starting crawl loop")
	for {
		<-ticker.C
		logrus.Info("Crawl started")

		blogs, err := repo.GetAllBlogs()
		if err != nil {
			logrus.WithError(err).Error("Error getting blog list")
			continue
		}

		for _, blog := range blogs {
			extractor.Crawl(blog)
			wp.Wait()
		}

		logrus.Info("Crawl finished")
	}
}