Missed main when converting to MVC

This commit is contained in:
Jason Streifling 2024-03-09 10:27:04 +01:00
parent c6b2a17220
commit 8530c76f2d

View File

@ -6,12 +6,13 @@ import (
"net/http"
"os"
"streifling.com/jason/cpolis/cmd/data"
"streifling.com/jason/cpolis/cmd/ui"
"streifling.com/jason/cpolis/cmd/control"
"streifling.com/jason/cpolis/cmd/model"
"streifling.com/jason/cpolis/cmd/view"
)
func init() {
gob.Register(data.User{})
gob.Register(model.User{})
}
func main() {
@ -23,45 +24,45 @@ func main() {
defer logFile.Close()
// log.SetOutput(logFile)
db, err := data.OpenDB("cpolis")
db, err := model.OpenDB("cpolis")
if err != nil {
log.Fatalln(err)
}
defer db.Close()
key, err := data.LoadKey("tmp/key.gob")
key, err := control.LoadKey("tmp/key.gob")
if err != nil {
key, err = data.NewKey()
key, err = control.NewKey()
if err != nil {
log.Fatalln(err)
}
data.SaveKey(key, "tmp/key.gob")
control.SaveKey(key, "tmp/key.gob")
}
store := data.NewCookieStore(key)
store := control.NewCookieStore(key)
mux := http.NewServeMux()
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
http.FileServer(http.Dir("web/static/"))))
mux.HandleFunc("/", ui.HomePage(db, store))
mux.HandleFunc("/", view.HomePage(db, store))
mux.HandleFunc("GET /create-tag/", ui.CreateTag)
mux.HandleFunc("GET /create-user/", ui.CreateUser)
mux.HandleFunc("GET /hub/", ui.ShowHub(store))
mux.HandleFunc("GET /rss/", ui.ShowRSS(
mux.HandleFunc("GET /create-tag/", view.CreateTag)
mux.HandleFunc("GET /create-user/", view.CreateUser)
mux.HandleFunc("GET /hub/", view.ShowHub(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 /unpublished-articles/", ui.ShowUnpublishedArticles(db))
mux.HandleFunc("GET /write-article/", ui.WriteArticle(db))
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(db))
mux.HandleFunc("GET /write-article/", view.WriteArticle(db))
mux.HandleFunc("POST /add-tag/", ui.AddTag(db, store))
mux.HandleFunc("POST /add-user/", ui.AddUser(db, store))
mux.HandleFunc("POST /finish-article/", ui.FinishArticle(db, store))
mux.HandleFunc("POST /login/", ui.Login(db, store))
mux.HandleFunc("POST /review-article/", ui.ReviewArticle(db, store))
mux.HandleFunc("POST /publish-article/", ui.PublishArticle(db, store))
mux.HandleFunc("POST /add-tag/", view.AddTag(db, store))
mux.HandleFunc("POST /add-user/", view.AddUser(db, store))
mux.HandleFunc("POST /finish-article/", view.FinishArticle(db, store))
mux.HandleFunc("POST /login/", view.Login(db, store))
mux.HandleFunc("POST /review-article/", view.ReviewArticle(db, store))
mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store))
log.Fatalln(http.ListenAndServe(":8080", mux))
}