Exemple #1
0
// Setup authentication and authorization keys for this app
func Setup(s *server.Server) {

	// Set up our secret keys which we take from the config
	// NB these are hex strings which we convert to bytes, for ease of presentation in secrets file
	c := s.Configuration()
	auth.HMACKey = auth.HexToBytes(c["hmac_key"])
	auth.SecretKey = auth.HexToBytes(c["secret_key"])
	auth.SessionName = "gohackernews"

	// Enable https cookies on production server - we don't have https, so don't do this
	//	if s.Production() {
	//		auth.SecureCookies = true
	//	}

}
Exemple #2
0
// Setup db - at present query pkg manages this...
func setupDatabase(server *server.Server) {
	defer server.Timef("#info Finished opening in %s database %s for user %s", time.Now(), server.Config("db"), server.Config("db_user"))

	config := server.Configuration()
	options := map[string]string{
		"adapter":  config["db_adapter"],
		"user":     config["db_user"],
		"password": config["db_pass"],
		"db":       config["db"],
	}

	// If host and port supplied in config, apply them
	if len(config["db_host"]) > 0 {
		options["host"] = config["db_host"]
	}
	if len(config["db_port"]) > 0 {
		options["port"] = config["db_port"]
	}
	if len(config["db_params"]) > 0 {
		options["params"] = config["db_params"]
	}

	// Ask query to open the database
	err := query.OpenDatabase(options)

	if err != nil {
		server.Fatalf("Error reading database %s", err)
	}

}
Exemple #3
0
// setupServices sets up external services from our config file
func setupServices(server *server.Server) {
	config := server.Configuration()

	context := schedule.NewContext(server.Logger, server)

	now := time.Now().UTC()

	// Set up twitter if available, and schedule tweets
	if config["twitter_secret"] != "" {
		twitter.Setup(config["twitter_key"], config["twitter_secret"], config["twitter_token"], config["twitter_token_secret"])

		tweetTime := time.Date(now.Year(), now.Month(), now.Day(), 11, 0, 0, 0, time.UTC)
		tweetInterval := 12 * time.Hour // Daily check for new stories to tweet twice a day

		// For testing
		//tweetTime = now.Add(time.Second * 5)

		schedule.At(storyactions.TweetTopStory, context, tweetTime, tweetInterval)
	}

	// Set up mail
	if config["mail_secret"] != "" {
		mail.Setup(config["mail_secret"], config["mail_from"])

		// Schedule emails to go out at 09:00 every day, starting from the next occurance
		emailTime := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.UTC)
		emailInterval := 24 * time.Hour // Daily check for new emails/texts to send

		// For testing send immediately on launch
		//emailTime = now.Add(time.Second * 2)

		schedule.At(useractions.DailyEmail, context, emailTime, emailInterval)
	}

}
Exemple #4
0
// Setup db - at present query pkg manages this...
func setupDatabase(server *server.Server) {
	defer server.Timef("#info Finished opening in %s database %s for user %s", time.Now(), server.Config("db"), server.Config("db_user"))

	config := server.Configuration()
	options := map[string]string{
		"adapter":  config["db_adapter"],
		"user":     config["db_user"],
		"password": config["db_pass"],
		"db":       config["db"],
	}

	// Ask query to open the database
	err := query.OpenDatabase(options)

	if err != nil {
		server.Fatalf("Error reading database %s", err)
	}

}