Esempio n. 1
0
func InitSQLStoreByDBChoice() SQLStore {
	cfg := config.LoadConfig()
	if cfg.DBChoice == "mysql" {
		return new(MySQLStore)
	} else if cfg.DBChoice == "postgres" {
		return new(PostgresStore)
	} else {
		panic("Invalid database choice found for `InitSQLStoreByDBChoice`.")
	}
}
Esempio n. 2
0
func OpenDBChoiceConnection() (*gorm.DB, error) {
	cfg := config.LoadConfig()

	if cfg.DBChoice == "mysql" {
		return mysql.OpenConnection()
	} else if cfg.DBChoice == "postgres" {
		return postgres.OpenConnection()
	} else {
		panic("Invalid database choice found for `OpenDBChoiceConnection`.")
	}
}
Esempio n. 3
0
// RunServer spins up the server and muxes the routes.
func RunServer(rssNotifier *rss.RSSNotifier) {
	// Load the config and initiate a `SQLStore` implementation.
	sqlObj := sqlStoreImpl.InitSQLStoreByDBChoice()
	cfg := config.LoadConfig()

	app := applicationContext{
		config:          cfg,
		trackerLevel:    a.RATIOLESS,
		peerStoreClient: new(redisPeerStoreImpl.RedisStore),
		sqlObj:          sqlObj,
		rssNotifier:     rssNotifier,
	}

	mux := http.NewServeMux()

	mux.HandleFunc("/announce", app.requestHandler)
	mux.HandleFunc("/scrape", app.scrapeHandler)
	if cfg.UseRSS == true {
		log.Println("Starting RSS handler at http://localhost/rss/")
		mux.HandleFunc("/rss/", app.rssHandle)
	}
	http.ListenAndServe(":3000", mux)
}
Esempio n. 4
0
// OpenConnection does as its name dictates and opens a connection to the
// MysqlHost listed in the config
func OpenConnection() (db *gorm.DB, err error) {
	c := config.LoadConfig()
	return OpenConnectionWithConfig(&c)
}