From 6c26099e513f530977c954353449e675a5839737 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 18 Feb 2016 12:16:35 +0100 Subject: Combine files --- assets.go | 8 -------- handler.go | 13 +++++++++++++ save.go | 17 ----------------- 3 files changed, 13 insertions(+), 25 deletions(-) delete mode 100644 assets.go delete mode 100644 save.go diff --git a/assets.go b/assets.go deleted file mode 100644 index 0905228..0000000 --- a/assets.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "net/http" - -func init() { - http.Handle("/css/", http.FileServer(http.Dir("assets"))) - http.Handle("/fonts/", http.FileServer(http.Dir("assets"))) -} 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) } diff --git a/save.go b/save.go deleted file mode 100644 index 68ac700..0000000 --- a/save.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import "net/http" - -func init() { - http.HandleFunc("/save/", saveHandler) -} - -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) -} -- cgit v1.2.3