package server import ( "html" "local/notes-server/filetree" "net/http" "path" "strings" ) func (s *Server) submit(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { http.NotFound(w, r) return } content := r.FormValue("content") content = html.UnescapeString(content) content = strings.ReplaceAll(content, "\r", "") err := s.Notes.Submit(r.URL.Path, content) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } url := *r.URL url.Path = path.Join("/notes/", filetree.NewPathFromURL(r.URL.Path).BaseHREF) http.Redirect(w, r, url.String(), http.StatusSeeOther) }