Make use of new gispatcho
This commit is contained in:
parent
c6975d3814
commit
e6b5ea3921
6 changed files with 22 additions and 59 deletions
|
|
@ -8,9 +8,9 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
urls "gitea.gwairfelin.com/max/gispatcho"
|
||||
"gitea.gwairfelin.com/max/gonotes/internal/conf"
|
||||
"gitea.gwairfelin.com/max/gonotes/internal/notes"
|
||||
"gitea.gwairfelin.com/max/gonotes/internal/urls"
|
||||
)
|
||||
|
||||
var myurls urls.URLs
|
||||
|
|
@ -31,13 +31,15 @@ func GetRoutes(prefix string) *http.ServeMux {
|
|||
func view(w http.ResponseWriter, r *http.Request) {
|
||||
title := r.PathValue("note")
|
||||
note, err := notes.LoadNote(title)
|
||||
urlEdit := myurls.Reverse("edit", urls.Repl{"note": title})
|
||||
if err != nil {
|
||||
http.Redirect(w, r, myurls.Reverse("edit", map[string]string{"note": title}), http.StatusFound)
|
||||
http.Redirect(w, r, urlEdit, http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
context := map[string]any{"note": note, "urlEdit": urlEdit}
|
||||
note.Render()
|
||||
err = renderTemplate(w, "view.html", note)
|
||||
err = renderTemplate(w, "view.html", context)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, "Couldn't load template", http.StatusInternalServerError)
|
||||
|
|
@ -52,7 +54,9 @@ func edit(w http.ResponseWriter, r *http.Request) {
|
|||
note = ¬es.Note{Title: title}
|
||||
}
|
||||
|
||||
err = renderTemplate(w, "edit.html", note)
|
||||
urlSave := myurls.Reverse("save", urls.Repl{"note": title})
|
||||
context := map[string]any{"note": note, "urlSave": urlSave}
|
||||
err = renderTemplate(w, "edit.html", context)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, "Couldn't load template", http.StatusInternalServerError)
|
||||
|
|
@ -65,7 +69,7 @@ func save(w http.ResponseWriter, r *http.Request) {
|
|||
body := r.FormValue("body")
|
||||
note := ¬es.Note{Title: title, Body: []byte(body)}
|
||||
note.Save()
|
||||
http.Redirect(w, r, myurls.Reverse("view", map[string]string{"note": title}), http.StatusFound)
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": title}), http.StatusFound)
|
||||
}
|
||||
|
||||
func list(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue