2024-02-18 07:20:51 +01:00
|
|
|
package main
|
|
|
|
|
2024-02-18 10:07:49 +01:00
|
|
|
import (
|
2024-03-03 09:16:49 +01:00
|
|
|
"encoding/gob"
|
2024-02-18 10:07:49 +01:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2024-02-24 11:41:01 +01:00
|
|
|
"os"
|
2024-02-18 10:07:49 +01:00
|
|
|
|
2024-02-18 16:37:13 +01:00
|
|
|
"streifling.com/jason/cpolis/cmd/data"
|
2024-02-24 09:54:25 +01:00
|
|
|
"streifling.com/jason/cpolis/cmd/ui"
|
2024-02-18 10:07:49 +01:00
|
|
|
)
|
2024-02-18 07:20:51 +01:00
|
|
|
|
2024-03-03 09:16:49 +01:00
|
|
|
func init() {
|
|
|
|
gob.Register(data.User{})
|
|
|
|
}
|
|
|
|
|
2024-02-18 07:20:51 +01:00
|
|
|
func main() {
|
2024-03-03 13:56:49 +01:00
|
|
|
logFile, err := os.OpenFile("tmp/cpolis.log",
|
|
|
|
os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
2024-02-24 11:41:01 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
defer logFile.Close()
|
|
|
|
log.SetOutput(logFile)
|
|
|
|
|
2024-02-18 16:37:13 +01:00
|
|
|
db, err := data.OpenDB("cpolis")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-02-22 19:27:41 +01:00
|
|
|
defer db.Close()
|
2024-02-18 16:37:13 +01:00
|
|
|
|
2024-03-05 17:13:59 +01:00
|
|
|
feed, err := data.LoadChannel("tmp/rss.gob")
|
2024-02-18 14:31:28 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2024-03-05 17:13:59 +01:00
|
|
|
feed = data.NewChannel("Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
2024-02-18 14:31:28 +01:00
|
|
|
"https://distrikt-ni-st.de",
|
|
|
|
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität")
|
|
|
|
}
|
2024-02-27 14:10:27 +01:00
|
|
|
|
2024-03-03 09:16:49 +01:00
|
|
|
key, err := data.LoadKey("tmp/key.gob")
|
|
|
|
if err != nil {
|
|
|
|
key, err = data.NewKey()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
data.SaveKey(key, "tmp/key.gob")
|
|
|
|
}
|
|
|
|
store := data.NewCookieStore(key)
|
|
|
|
|
2024-03-05 18:20:34 +01:00
|
|
|
articleList, err := data.LoadArticleList("tmp/unpublished-articles.gob")
|
2024-03-03 13:56:49 +01:00
|
|
|
if err != nil {
|
|
|
|
articleList = data.NewArticleList()
|
|
|
|
}
|
|
|
|
|
|
|
|
tagList, err := data.LoadTagList("tmp/tags.gob")
|
|
|
|
if err != nil {
|
|
|
|
tagList = data.NewTagList()
|
|
|
|
}
|
2024-02-18 10:07:49 +01:00
|
|
|
|
2024-02-18 14:31:28 +01:00
|
|
|
mux := http.NewServeMux()
|
2024-02-18 10:07:49 +01:00
|
|
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
|
2024-03-03 09:16:49 +01:00
|
|
|
mux.HandleFunc("/", ui.HomePage(db, store))
|
2024-02-24 10:56:12 +01:00
|
|
|
|
2024-03-03 13:56:49 +01:00
|
|
|
mux.HandleFunc("GET /create-tag/", ui.CreateTag)
|
|
|
|
mux.HandleFunc("GET /create-user/", ui.CreateUser)
|
2024-03-03 09:16:49 +01:00
|
|
|
mux.HandleFunc("GET /hub/", ui.ShowHub(store))
|
|
|
|
mux.HandleFunc("GET /rss/", ui.ShowRSS(feed))
|
2024-03-03 13:56:49 +01:00
|
|
|
mux.HandleFunc("GET /unpublished-articles/", ui.ShowUnpublishedArticles(articleList))
|
|
|
|
mux.HandleFunc("GET /write-article/", ui.WriteArticle(tagList))
|
2024-03-01 11:30:31 +01:00
|
|
|
|
2024-03-03 13:56:49 +01:00
|
|
|
mux.HandleFunc("POST /add-tag/", ui.AddTag(tagList, store))
|
|
|
|
mux.HandleFunc("POST /add-user/", ui.AddUser(db, store))
|
2024-03-03 09:16:49 +01:00
|
|
|
mux.HandleFunc("POST /finish-article/", ui.FinishArticle(articleList, store))
|
|
|
|
mux.HandleFunc("POST /login/", ui.Login(db, store))
|
|
|
|
mux.HandleFunc("POST /review-article/", ui.ReviewArticle(articleList, store))
|
|
|
|
mux.HandleFunc("POST /publish-article/", ui.PublishArticle(feed, articleList, store))
|
2024-02-18 10:07:49 +01:00
|
|
|
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
2024-02-18 07:20:51 +01:00
|
|
|
}
|