lets-go:9.3 sessions
This commit is contained in:
parent
5ad766f20c
commit
bf9dcd1247
@ -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)
|
||||
}
|
||||
|
@ -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"),
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ type templateData struct {
|
||||
Snippet models.Snippet
|
||||
Snippets []models.Snippet
|
||||
Form any
|
||||
Flash string
|
||||
}
|
||||
|
||||
// humanDate ...
|
||||
|
@ -14,6 +14,9 @@
|
||||
</header>
|
||||
{{template "nav" .}}
|
||||
<main>
|
||||
{{with .Flash}}
|
||||
<div class="flash">{{.}}</div>
|
||||
{{end}}
|
||||
{{template "main" .}}
|
||||
</main>
|
||||
<footer>
|
||||
|
Loading…
Reference in New Issue
Block a user