aboutsummaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/handler.go b/handler.go
index 04d6d94..369da40 100644
--- a/handler.go
+++ b/handler.go
@@ -7,10 +7,13 @@ import (
)
func init() {
+ http.Handle("/css/", http.FileServer(http.Dir("assets")))
+ http.Handle("/fonts/", http.FileServer(http.Dir("assets")))
http.HandleFunc("/index", indexHandler)
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/del/", delHandler)
+ http.HandleFunc("/save/", saveHandler)
http.HandleFunc("/", homeHandler)
}
@@ -62,6 +65,16 @@ func delHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound)
}
+func saveHandler(w http.ResponseWriter, r *http.Request) {
+ title := r.URL.Path[len("/save/"):]
+ p := &Page{Title: title, Body: []byte(r.FormValue("body"))}
+ if err := p.save(); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ http.Redirect(w, r, "/view/"+title, http.StatusFound)
+}
+
func homeHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/view/Home", http.StatusFound)
}