blob: 5cf44cf829b7414e086f7b2cb592017cfb17d616 (
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
|
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
Team string
}{
Challenges: challenges,
Team: session.Team,
}); err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
}
}
|