package handlers import ( "log" "net/http" "path/filepath" "github.com/gorilla/sessions" ) func HomeHandler(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 cookie, _ := r.Cookie("threadr_cookie_banner") data := struct { PageData }{ PageData: PageData{ Title: "ThreadR - Home", Navbar: "home", LoggedIn: loggedIn, ShowCookieBanner: cookie == nil || cookie.Value == "", BasePath: app.Config.ThreadrDir, StaticPath: filepath.Join(app.Config.ThreadrDir, "static"), CurrentURL: r.URL.String(), }, } if err := app.Tmpl.ExecuteTemplate(w, "home", data); err != nil { log.Printf("Error executing template in HomeHandler: %v", err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } } }