80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"streifling.com/jason/cpolis/cmd/data"
|
|
"streifling.com/jason/cpolis/cmd/ui"
|
|
)
|
|
|
|
func init() {
|
|
gob.Register(data.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 := data.OpenDB("cpolis")
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
feed, err := data.LoadChannel("tmp/rss.gob")
|
|
if err != nil {
|
|
log.Println(err)
|
|
feed = data.NewChannel("Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
|
"https://distrikt-ni-st.de",
|
|
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität")
|
|
}
|
|
|
|
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)
|
|
|
|
articleList, err := data.LoadArticleList("tmp/unpublished-articles.gob")
|
|
if err != nil {
|
|
articleList = data.NewArticleList()
|
|
}
|
|
|
|
tagList, err := data.LoadTagList("tmp/tags.gob")
|
|
if err != nil {
|
|
tagList = data.NewTagList()
|
|
}
|
|
|
|
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("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(feed))
|
|
mux.HandleFunc("GET /unpublished-articles/", ui.ShowUnpublishedArticles(articleList))
|
|
mux.HandleFunc("GET /write-article/", ui.WriteArticle(tagList))
|
|
|
|
mux.HandleFunc("POST /add-tag/", ui.AddTag(tagList, store))
|
|
mux.HandleFunc("POST /add-user/", ui.AddUser(db, store))
|
|
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))
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
|
}
|