Пример #1
0
func StartServer(serverAddress string, cookieStoreSalt string) {

	//gob is used when we save failed form structs to the session
	gob.Register(CreateAccount{})
	gob.Register(fact.Fact{})

	decoder.RegisterConverter(false, ConvertBool)

	fyidb.ConnectDatabase("heyfyi")

	store = sessions.NewCookieStore([]byte(cookieStoreSalt))

	router := initRouter()

	go BackgroundVoteGiver()

	log.Println("Server running at " + serverAddress)
	if err := http.ListenAndServe(serverAddress, router); err != nil {
		log.Println("Error:", err.Error())
	}
}
Пример #2
0
func StartServer(logFileName string, serverAddress string) {

	f, err := os.OpenFile(logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		panic("Can't open log file: " + err.Error())
	}
	log.SetOutput(io.MultiWriter(f, os.Stdout))

	/* On platforms like heroky/dokku this should be PORT, not HTTP_PORT. */
	HTTP_PORT = os.Getenv("HTTP_PORT")
	if len(HTTP_PORT) == 0 {
		log.Println("$HTTP_PORT was not set, defaulting to 3000")
		HTTP_PORT = "3000"
	}

	COOKIE_STORE_SALT = os.Getenv("COOKIE_STORE_SALT")
	if len(COOKIE_STORE_SALT) == 0 {
		log.Fatal("$COOKIE_STORE_SALT was not set, cannot go on. Exiting.")
	} else {
		store = sessions.NewCookieStore([]byte("9s7YD807h*&DHhihSD123434SASDD__834HUSJNCxczc123!@#sd85"))
	}

	//gob is used when we save failed form structs to the session
	gob.Register(CreateAccount{})
	gob.Register(fact.Fact{})

	decoder.RegisterConverter(false, ConvertBool)

	fyidb.ConnectDatabase("heyfyi")

	router := initRouter()

	go BackgroundVoteGiver()

	log.Println("Server running at " + serverAddress)
	if err := http.ListenAndServe(":"+HTTP_PORT, router); err != nil {
		log.Println("Error:", err.Error())
	}
}