Experimenting with sessions
This commit is contained in:
@ -29,6 +29,9 @@ func NewHandlers(r *Repository) {
|
||||
|
||||
// Home is the about page handler
|
||||
func (m *Repository) Home(w http.ResponseWriter, r *http.Request) {
|
||||
remoteIP := r.RemoteAddr
|
||||
m.App.Session.Put(r.Context(), "remote_ip", remoteIP)
|
||||
|
||||
render.RenderTemplate(w, "home.page.tmpl", &models.TemplateData{})
|
||||
}
|
||||
|
||||
@ -37,6 +40,10 @@ func (m *Repository) About(w http.ResponseWriter, r *http.Request) {
|
||||
// perform some logic
|
||||
stringMap := make(map[string]string)
|
||||
stringMap["test"] = "Hello world!"
|
||||
|
||||
remoteIP := m.App.Session.GetString(r.Context(), "remote_ip")
|
||||
stringMap["remote_ip"] = remoteIP
|
||||
|
||||
// send the data to the template
|
||||
render.RenderTemplate(w, "about.page.tmpl", &models.TemplateData{StringMap: stringMap})
|
||||
}
|
||||
|
Reference in New Issue
Block a user