aboutsummaryrefslogtreecommitdiff
path: root/save.go
diff options
context:
space:
mode:
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)
+}