s1llyw0rdz/web/handler/index_show.go

36 lines
711 B
Go
Raw Normal View History

2021-11-22 09:06:23 +00:00
package handler
import (
"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-11-26 22:36:48 +00:00
user, _ := h.sess.Get(r)
2021-11-22 17:12:07 +00:00
statuses, err := h.storage.LatestStatuses()
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{}{
"statuses": statuses,
2021-11-22 20:23:30 +00:00
"flash": flash,
2021-12-02 20:41:17 +00:00
"status": &model.Status{},
2021-11-26 22:36:48 +00:00
}, user)
2021-11-22 09:06:23 +00:00
}