s1llyw0rdz/web/handler/index_show.go

39 lines
819 B
Go
Raw Normal View History

2021-11-22 09:06:23 +00:00
package handler
import (
2021-12-22 11:04:24 +00:00
"github.com/gorilla/csrf"
2021-11-22 09:06:23 +00:00
"net/http"
2021-12-02 20:41:17 +00:00
"status/model"
2021-11-22 09:06:23 +00:00
)
type Update struct {
UpdatedAgo string
Author string
}
func (h *Handler) showIndexView(w http.ResponseWriter, r *http.Request) {
2021-12-06 06:14:20 +00:00
protectClickJacking(w)
2021-11-26 22:36:48 +00:00
user, _ := h.sess.Get(r)
statuses, err := h.storage.StatusFeed()
2021-11-22 17:12:07 +00:00
if err != nil {
serverError(w, err)
return
}
2021-11-26 22:36:48 +00:00
session, err := h.sess.Store.Get(r, "status")
2021-11-22 20:23:30 +00:00
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
flash := ""
if flashes := session.Flashes(); len(flashes) > 0 {
flash = flashes[0].(string)
}
session.Save(r, w)
2021-11-22 17:12:07 +00:00
h.renderLayout(w, "index", map[string]interface{}{
2021-12-22 11:04:24 +00:00
"statuses": statuses,
"flash": flash,
"status": &model.Status{},
csrf.TemplateTag: csrf.TemplateField(r),
2021-11-26 22:36:48 +00:00
}, user)
2021-11-22 09:06:23 +00:00
}