blob: 9279151f3a6f8765f7bb063866cfd0f8663e9a4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package handler
import (
"html/template"
"log"
"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 {
log.Printf("Could not list repositories: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
session := r.Context().Value("session").(*session.UserSession)
if err := tmpl.ExecuteTemplate(w, "index.html", struct {
Challenges []string
Name string
Team string
}{
Challenges: challenges,
Name: session.Name,
Team: session.TeamName,
}); err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
}
}
|