lets-go:9.3 sessions

This commit is contained in:
tamsin johnson 2024-02-06 21:37:06 -08:00
parent 5ad766f20c
commit bf9dcd1247
4 changed files with 7 additions and 0 deletions

View File

@ -97,5 +97,7 @@ func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request
return
}
app.sessionManager.Put(r.Context(), "flash", "Snippet successfully created!")
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
}

View File

@ -16,6 +16,7 @@ import (
func (app *application )newTemplateData(r *http.Request) templateData {
return templateData{
CurrentYear: time.Now().Year(),
Flash: app.sessionManager.PopString(r.Context(), "flash"),
}
}

View File

@ -13,6 +13,7 @@ type templateData struct {
Snippet models.Snippet
Snippets []models.Snippet
Form any
Flash string
}
// humanDate ...

View File

@ -14,6 +14,9 @@
</header>
{{template "nav" .}}
<main>
{{with .Flash}}
<div class="flash">{{.}}</div>
{{end}}
{{template "main" .}}
</main>
<footer>