summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..9eaebcc
--- /dev/null
+++ b/main.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "github.com/gorilla/mux"
+ "github.com/kch42/simpleconf"
+ _ "kch42.de/gostuff/mailremind/model/mysql"
+ "log"
+ "net/http"
+)
+
+func debug(rw http.ResponseWriter, req *http.Request) {
+ fmt.Fprintf(rw, "Content-Type: text/plain\r\n\r\n%#v", req)
+}
+
+var conf simpleconf.Config
+var baseurl string
+
+func main() {
+ confpath := flag.String("config", "", "Path to config file")
+ flag.Parse()
+
+ var err error
+ if conf, err = simpleconf.LoadByFilename(*confpath); err != nil {
+ log.Fatalf("Could not read config: %s", err)
+ }
+
+ if baseurl, err = conf.GetString("web", "baseurl"); err != nil {
+ log.Fatalf("Could not get web.baseurl from config: %s", err)
+ }
+
+ initTpls()
+ loadTimeLocs()
+ initMailing()
+ initMails()
+ initDB()
+ defer dbcon.Close()
+
+ staticpath, err := conf.GetString("paths", "static")
+ if err != nil {
+ log.Fatalf("Could not get paths.static config: %s", err)
+ }
+
+ laddr, err := conf.GetString("net", "laddr")
+ if err != nil {
+ log.Fatalf("Could not get net.laddr config: %s", err)
+ }
+
+ router := mux.NewRouter()
+ router.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticpath))))
+ router.HandleFunc("/register", register)
+
+ http.Handle("/", router)
+
+ if err := http.ListenAndServe(laddr, nil); err != nil {
+ log.Fatalf("Could not ListenAndServe: %s", err)
+ }
+}