cpolis/main.go

55 lines
1.5 KiB
Go
Raw Normal View History

2024-02-18 07:20:51 +01:00
package main
import (
"log"
"net/http"
2024-02-24 11:41:01 +01:00
"os"
"streifling.com/jason/cpolis/cmd/data"
2024-02-24 09:54:25 +01:00
"streifling.com/jason/cpolis/cmd/ui"
)
2024-02-18 07:20:51 +01:00
func main() {
2024-02-24 11:41:01 +01:00
logFile, err := os.Create("tmp/cpolis.log")
if err != nil {
log.Fatalln(err)
}
defer logFile.Close()
log.SetOutput(logFile)
db, err := data.OpenDB("cpolis")
if err != nil {
log.Fatalln(err)
}
2024-02-22 19:27:41 +01:00
defer db.Close()
2024-02-24 14:49:29 +01:00
feed, err := data.OpenFeed("tmp/rss.gob")
if err != nil {
log.Println(err)
2024-02-24 14:49:29 +01:00
feed = data.NewFeed("Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
"https://distrikt-ni-st.de",
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität")
}
2024-03-01 21:01:38 +01:00
articleList := data.NewArticleList()
mux := http.NewServeMux()
mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
2024-03-01 12:25:53 +01:00
mux.HandleFunc("/", ui.HomePage(db))
2024-03-01 11:30:31 +01:00
mux.HandleFunc("/rss/", ui.ShowRSS(feed))
mux.HandleFunc("GET /hub/", ui.ShowHub())
2024-02-24 14:49:29 +01:00
mux.HandleFunc("POST /add-user/", ui.AddUser(db))
2024-02-24 15:31:33 +01:00
mux.HandleFunc("POST /create-user/", ui.CreateUser())
mux.HandleFunc("POST /finish-article/", ui.FinishArticle(articleList))
2024-02-24 14:49:29 +01:00
mux.HandleFunc("POST /login/", ui.Login(db))
2024-03-01 11:30:31 +01:00
mux.HandleFunc("POST /review-article/", ui.ReviewArticle(articleList))
mux.HandleFunc("POST /publish-article/", ui.PublishArticle(feed, articleList))
mux.HandleFunc("POST /unpublished-articles/", ui.ShowUnpublishedArticles(articleList))
mux.HandleFunc("POST /write-article/", ui.WriteArticle())
log.Fatalln(http.ListenAndServe(":8080", mux))
2024-02-18 07:20:51 +01:00
}