package main import ( "encoding/gob" "log" "net/http" "os" "streifling.com/jason/cpolis/cmd/control" "streifling.com/jason/cpolis/cmd/model" "streifling.com/jason/cpolis/cmd/view" ) func init() { gob.Register(model.User{}) } func main() { logFile, err := os.OpenFile("tmp/cpolis.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatalln(err) } defer logFile.Close() // log.SetOutput(logFile) db, err := model.OpenDB("cpolis") if err != nil { log.Fatalln(err) } defer db.Close() key, err := control.LoadKey("tmp/key.gob") if err != nil { key, err = control.NewKey() if err != nil { log.Fatalln(err) } control.SaveKey(key, "tmp/key.gob") } store := control.NewCookieStore(key) mux := http.NewServeMux() mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/")))) mux.HandleFunc("/", view.HomePage(db, store)) mux.HandleFunc("GET /create-tag/", view.CreateTag) mux.HandleFunc("GET /create-user/", view.CreateUser) mux.HandleFunc("GET /edit-user/", view.EditUser(db, store)) mux.HandleFunc("GET /hub/", view.ShowHub(db, store)) mux.HandleFunc("GET /logout/", view.Logout(store)) mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(db)) mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(db, store)) mux.HandleFunc("GET /rss/", view.ShowRSS( db, "Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt", "https://distrikt-ni-st.de", "Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität", )) mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(db)) mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(db)) mux.HandleFunc("GET /write-article/", view.WriteArticle(db)) mux.HandleFunc("POST /add-tag/", view.AddTag(db, store)) mux.HandleFunc("POST /add-user/", view.AddUser(db, store)) mux.HandleFunc("POST /login/", view.Login(db, store)) mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store)) mux.HandleFunc("POST /reject-article/", view.RejectArticle(db, store)) mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(db, store)) mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store)) mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store)) mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store)) mux.HandleFunc("POST /update-user/", view.UpdateUser(db, store)) log.Fatalln(http.ListenAndServe(":8080", mux)) }