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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.sessionManager.Put(r.Context(), "flash", "Snippet successfully created!")
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
|
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 {
|
func (app *application )newTemplateData(r *http.Request) templateData {
|
||||||
return templateData{
|
return templateData{
|
||||||
CurrentYear: time.Now().Year(),
|
CurrentYear: time.Now().Year(),
|
||||||
|
Flash: app.sessionManager.PopString(r.Context(), "flash"),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ type templateData struct {
|
|||||||
Snippet models.Snippet
|
Snippet models.Snippet
|
||||||
Snippets []models.Snippet
|
Snippets []models.Snippet
|
||||||
Form any
|
Form any
|
||||||
|
Flash string
|
||||||
}
|
}
|
||||||
|
|
||||||
// humanDate ...
|
// humanDate ...
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
</header>
|
</header>
|
||||||
{{template "nav" .}}
|
{{template "nav" .}}
|
||||||
<main>
|
<main>
|
||||||
|
{{with .Flash}}
|
||||||
|
<div class="flash">{{.}}</div>
|
||||||
|
{{end}}
|
||||||
{{template "main" .}}
|
{{template "main" .}}
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
|
Loading…
Reference in New Issue
Block a user