Exemple #1
0
func main() {
	db.DB, err = sql.Open("postgres", config.GetValue("DATABASE_URL"))
	defer db.DB.Close()

	if err != nil {
		log.Fatalln("Error DB open:", err.Error())
	}

	if err = db.DB.Ping(); err != nil {
		log.Fatalln("Error DB ping:", err.Error())
	}

	log.Println("Connected to DB")

	testData := flag.Bool("test-data", false, "to load test data")
	resetDB := flag.Bool("reset-db", false, "reset the database")
	flag.Parse()

	initial.Init(*resetDB, *testData)

	// base := new(controllers.BaseController)
	// base.Index().LoadContestsFromCats()

	http.Handle("/", new(router.FastCGIServer))
	http.HandleFunc("/wellcometoprofile/", controllers.WellcomeToProfile)
	http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./static/js"))))
	http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./static/css"))))
	http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("./static/img"))))

	addr := config.GetValue("HOSTNAME") + ":" + config.GetValue("PORT")
	log.Println("Server listening on", addr)
	log.Fatalln("Error listening:", http.ListenAndServe(addr, nil))
}
Exemple #2
0
func main() {
	log.Println("Server started.")

	db.DB, err = sql.Open("postgres", config.GetValue("DATABASE_URL"))
	defer db.DB.Close()

	if err != nil {
		log.Println("Error db connection: ", err.Error())
		os.Exit(1)
	}

	log.Println("DB CONNECTED")

	testData := flag.Bool("test-data", false, "to load test data")
	resetDB := flag.Bool("reset-db", false, "reset the database")
	flag.Parse()

	if *resetDB == true {
		new(controllers.BaseController).IndexController().Init(*testData)
		resources.LoadAdmin()
		resources.LoadParamTypes()
	}

	if *testData == true {
		resources.Load()
	}

	// base := new(controllers.BaseController)
	// base.Index().LoadContestsFromCats()

	http.Handle("/", new(router.FastCGIServer))
	http.HandleFunc("/wellcometoprofile/", controllers.WellcomeToProfile)
	http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./static/js"))))
	http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./static/css"))))
	http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("./static/img"))))

	port := config.GetValue("PORT")
	if port == "" {
		port = "5000"
	}

	if err := http.ListenAndServe(":"+port, nil); err != nil {
		log.Println("Error listening: ", err.Error())
		os.Exit(1)
	}
}
Exemple #3
0
type SmtpTemplateData struct {
	From            string
	To              string
	Subject         string
	ConfirmationUrl string
	RejectionUrl    string
	EventName       string
	EventUrl        string
	HeadName        string
	GroupName       string
	Login           string
	Password        string
}

var Admin_ = &Admin{
	Name:       config.GetValue("ADMIN_NAME"),
	Email:      config.GetValue("EMAIL"),
	Password:   config.GetValue("EMAIL_PASSWORD"),
	SMTPServer: config.GetValue("SMTP_SERVER"),
	Port:       config.GetValue("SMTP_PORT")}

var auth = smtp.PlainAuth(
	"",
	Admin_.Email,
	Admin_.Password,
	Admin_.SMTPServer)

func SendEmail(address, tmp string, context *SmtpTemplateData) bool {
	var doc bytes.Buffer
	template.Must(template.New("email").Parse(tmp)).Execute(&doc, context)