package handler import ( "html/template" "log/slog" "net/http" "git.leonardobishop.net/instancer/pkg/registry" "git.leonardobishop.net/instancer/pkg/session" ) func GetIndex(tmpl *template.Template, registryClient *registry.RegistryClient) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { challenges, err := registryClient.ListRepositories() if err != nil { slog.Error("could not list repositories", "cause", err) tmpl.ExecuteTemplate(w, "problem.html", struct { Error string ShowLogout bool }{ Error: "Error occured fetching available challenges. Please try again.", ShowLogout: false, }) return } session := r.Context().Value("session").(*session.UserSession) tmpl.ExecuteTemplate(w, "index.html", struct { Challenges []string Name string Team string }{ Challenges: challenges, Name: session.Name, Team: session.TeamName, }) } }