s1llyw0rdz/web/handler/index_show.go
2021-11-22 21:23:30 +01:00

39 lines
734 B
Go

package handler
import (
"fmt"
"net/http"
)
type Update struct {
UpdatedAgo string
Author string
}
func (h *Handler) showIndexView(w http.ResponseWriter, r *http.Request) {
user, err := h.getUser(r)
if err != nil {
unauthorized(w)
return
}
statuses, err := h.storage.LatestStatuses()
if err != nil {
serverError(w, err)
return
}
session, err := h.sess.Store.Get(r, "ichi")
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)
fmt.Println(user)
h.renderLayout(w, "index", map[string]interface{}{
"statuses": statuses,
"flash": flash,
}, "")
}