diff --git a/cmd/ui/handlers.go b/cmd/ui/handlers.go index 781f764..2504c08 100644 --- a/cmd/ui/handlers.go +++ b/cmd/ui/handlers.go @@ -29,7 +29,7 @@ func Login(db *data.DB) http.HandlerFunc { return } - template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil) + template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil) } } @@ -54,13 +54,7 @@ func FinishEdit(feed *data.Feed) http.HandlerFunc { }) feed.Save("tmp/rss.gob") - rss, err := feed.ToRss() - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - template.Must(template.ParseFiles("web/templates/feed.rss")).ExecuteTemplate(w, "page-content", rss) + template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil) } } @@ -124,6 +118,30 @@ func AddUser(db *data.DB) http.HandlerFunc { http.Error(w, err.Error(), http.StatusInternalServerError) return } - template.Must(template.ParseFiles("web/templates/editor.html")).Execute(w, nil) + template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil) + } +} + +func WriteArticle() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil) + } +} + +func ShowRSS(feed *data.Feed) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + rss, err := feed.ToRss() + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + template.Must(template.ParseFiles("web/templates/index.html", "web/templates/feed.rss")).Execute(w, rss) + } +} + +func CreateUser() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", nil) } } diff --git a/main.go b/main.go index 05b8ee3..7c9c72c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "html/template" "log" "net/http" @@ -40,7 +39,6 @@ func main() { if err != nil { log.Fatalln(err) } - fmt.Println(numRows) if numRows == 0 { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { template.Must(template.ParseFiles("web/templates/index.html", "web/templates/add-user.html")).Execute(w, nil) @@ -52,8 +50,11 @@ func main() { } mux.HandleFunc("POST /add-user/", ui.AddUser(db)) - mux.HandleFunc("POST /finished-edit/", ui.FinishEdit(feed)) + mux.HandleFunc("POST /create-user/", ui.CreateUser()) + mux.HandleFunc("POST /write-article/", ui.WriteArticle()) + mux.HandleFunc("POST /finish-edit/", ui.FinishEdit(feed)) mux.HandleFunc("POST /login/", ui.Login(db)) + mux.HandleFunc("/rss/", ui.ShowRSS(feed)) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/web/templates/editor.html b/web/templates/editor.html index 976cdb0..c3aab1b 100644 --- a/web/templates/editor.html +++ b/web/templates/editor.html @@ -4,7 +4,7 @@ - + {{end}} diff --git a/web/templates/hub.html b/web/templates/hub.html new file mode 100644 index 0000000..5103d6b --- /dev/null +++ b/web/templates/hub.html @@ -0,0 +1,6 @@ +{{define "page-content"}} +

Hub

+ + + +{{end}}