threadr-rewritten/handlers/news.go

38 lines
1.3 KiB
Go

package handlers
import (
"log"
"net/http"
"github.com/gorilla/sessions"
)
func NewsHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil
newsItems := []string{
"2020-02-21 Whole Website updated: Homepage, News, Boards, About, Log In, Userhome, Log Out",
"2020-01-06 First Steps done",
}
data := struct {
PageData
News []string
}{
PageData: PageData{
Title: "ThreadR - News",
Navbar: "news",
LoggedIn: loggedIn,
ShowCookieBanner: true,
BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path,
},
News: newsItems,
}
if err := app.Tmpl.ExecuteTemplate(w, "news", data); err != nil {
log.Printf("Error executing template in NewsHandler: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
}
}