package handlers import ( "net/http" ) // HandleIndex returns a handler for the root path that redirects // based on authentication state: authenticated users go to /sources // (the dashboard), unauthenticated users go to the login page. func (s *Handlers) HandleIndex() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { sess, err := s.session.Get(r) if err == nil && s.session.IsAuthenticated(sess) { http.Redirect(w, r, "/sources", http.StatusSeeOther) return } http.Redirect(w, r, "/pages/login", http.StatusSeeOther) } }