package main import ( "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/gorilla/sessions" "html/template" "log" "net/http" "os" ) var decoder = schema.NewDecoder() 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")) 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.HandleFunc("/register", RegisterHandler) r.HandleFunc("/privacy", PrivacyHandler) r.HandleFunc("/tos", TosHandler) r.HandleFunc("/about", AboutHandler) r.HandleFunc("/howto", HowtoHandler) r.HandleFunc("/server", ServerHandler) r.HandleFunc("/create", CreateNewEntryHandler).Methods("POST") r.HandleFunc("/user", UserHandler) r.HandleFunc("/password", PasswordHandler) r.HandleFunc("/changePassword", ChangePasswordHandler).Methods("POST") r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static")))) r.HandleFunc("/locale", ChangeLocaleHandler) http.Handle("/", r) ip := os.Getenv("FREEMAIL_HTTP_IP") port := os.Getenv("FREEMAIL_HTTP_PORT") err := http.ListenAndServe(ip+":"+port, nil) if err != nil { log.Panic("Info: ", err) } log.Println("Info: Server is up and listens on " + ip + ":" + port) }