aboutsummaryrefslogtreecommitdiff
path: root/save.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-02-16 18:43:22 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-02-16 18:43:22 +0100
commit8bf5d9d2c82560c81be6809522215bded0cf9911 (patch)
tree82df16f1e2b3d130b63a910df55e22a124d56c5b /save.go
Inital import
Diffstat (limited to 'save.go')
-rw-r--r--save.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/save.go b/save.go
new file mode 100644
index 0000000..68ac700
--- /dev/null
+++ b/save.go
@@ -0,0 +1,17 @@
+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)
+}