From f334c93c0364d14a2b55641b155ad58f715a4b39 Mon Sep 17 00:00:00 2001 From: horus_arch Date: Thu, 19 Mar 2015 13:39:37 +0100 Subject: Rewriting from scratch. --- main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..b18bd8d --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "github.com/gorilla/mux" + "github.com/gorilla/schema" + "github.com/gorilla/sessions" + "github.com/robfig/cron" + "html/template" + "log" + "net/http" + "os" +) + +var decoder = schema.NewDecoder() + +//var store = sessions.NewCookieStore([]byte(RandomKey())) +var store = sessions.NewCookieStore([]byte(os.Getenv("FREEMAIL_SECRET"))) + +var mainTempl = template.Must(template.New("global").Funcs(template.FuncMap{"add": add}).ParseGlob("./views/*.html")) +var emailTempl = template.Must(template.New("email").Funcs(template.FuncMap{"add": add}).ParseGlob("./views/email/*.html")) + +var c = cron.New() + +func add(x, y int) int { + return x + y +} + +func main() { + decoder.IgnoreUnknownKeys(true) + store.Options = &sessions.Options{ + Path: "/", + MaxAge: 86400, + HttpOnly: true, + } + checkConfig() + InitDB() + + r := mux.NewRouter() + // r.HandleFunc("/", IndexHandler) + r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./../static")))) + + http.Handle("/", r) + + ip := os.Getenv("FREEMAIL_HTTP_IP") + port := os.Getenv("FREEMAIL_HTTP_PORT") + + http.ListenAndServe(ip+":"+port, nil) + log.Println("Ales oke") +} -- cgit v1.2.3